Closed sdoeringNew closed 3 years ago
I don't see this as a bug because the use cases for this are pretty small.
The solution would be to put this:
// Restore the Jenkins.HOLDER
// It was overwritten in: JenkinsPipelineSpecification#setup()
Jenkins.HOLDER = new Jenkins.JenkinsHolder() {
Jenkins getInstance() { Jenkins.theInstance }
}
in the cleanup()
of the JenkinsPipelineSpecification
.
In case someone stumbles upon this issue as well I've workarounded this issue by adding a second ClassRule before the JenkinsRule
that restores the Jenkins.HOLDER
like that:
@Shared
@ClassRule
CleanJenkinsHolderRule cleanJenkinsHolderRule = new CleanJenkinsHolderRule()
@Shared
@ClassRule
JenkinsRule jenkinsRule = new JenkinsRule()
static class CleanJenkinsHolderRule implements TestRule {
Statement apply(Statement base, Description description) {
// Restore the Jenkins.HOLDER
// It was overwritten in: JenkinsPipelineSpecification#setup()
Jenkins.HOLDER = new Jenkins.JenkinsHolder() {
Jenkins getInstance() { Jenkins.theInstance }
}
return { base.evaluate() } as Statement
}
}
Of course you could add a cleanup()
to every JenkinsPipelineSpecification
and restore the Jenkins.HOLDER
there.
I like the rule-based solution (workaround?), given that the problem is introduced by using a JenkinsRule
in the first place.
I'll file this as FAQ, and hope to eventually include it in wiki-based documentation when we move out of "just Groovydoc."
Desired Behavior
If a
JenkinsPipelineSpecification
test runs before a test with theJenkinsRule
that latter test will fail with an unspecificNullPointerException
about anUser
:To workaround this issue it is necessary to restore the
Jenkins.HOLDER
that theJenkinsPipelineSpecification
has overwritten.Benefits
With this change it would be possible to run both
JenkinsPipelineSpecification
andJenkinsRule
tests.