Closed masterzen closed 6 years ago
Hi, thanks for reporting.
Indeed, this is a case that I try to circumvent.
If a job dsl extension behaves this way (assuming a Jenkins instance is running and doing stuff with it) you are basically out of luck for testing it all locally. At least the basic test support does not support it (right now).
You are right in that a fake Jenkins instance or a mock could be a possible solution but depending on the needs of the Job DSL extension this could be a deep rabbit hole which is why I chose to not support it.
That said, all built in Job DSL methods and most of the extensions I found are merely XML generators (as it should be) and can be used safely. The Github Pull Request Builder is sadly not on this list :(
After having an intense look into the test code ;-) there might be the possibility to use the Jenkins test harness to support this.
I will have to investigate on this but it might take some time.
Your snippets should be enough for a test case.
@carstenlenz thanks! If you need any help let me know :)
Kind of embarassing but I think this issue should be fixed with 2.0.0.
I close this issue for now as the plugin has changed significantly with the 2.0.0 release. Feel free to reopen.
The following snippets triggers a NPE:
The gradle build file contains the extension:
This produces the following exception:
The problem is that when the
githubPullRequest
extension is created, it creates a Trigger jenkins Extension which in turn loads itsDescriptor
which in turn usesJenkings.getInstance()
(in order to load the main jenkins config file). Since jenkins is not initialized,Jenkins.getInstance()
returns null and there's an NPE.I can't think of any workaround besides injecting a fake Jenkins instance (or a mock?).