Provide JenkinsRule.restart()
implementation
#716
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Thanks to #438 there is now support for JUnit5. However there are still some open points or missing features from JUnit4 evolving around
JenkinsRule
.Problem
While trying to upgrade the plugin archetypes to use JUnit5 (jenkinsci/archetypes#691) I encountered one of these open points: Right now there is no implementation that resembles
RestartableJenkinsRule
orJenkinsSessionRule
for JUnit5.After giving it a try myself to get such an implementation going I quickly found that it will likely require a huge portion of refactoring and changing behavior of
JenkinsRule
/JUnit5JenkinsRule
.Even though I do think that at some point one might need to bite the bullet and fully re-write most of the implementation for JUnit5 and dropping support for JUnit4 - this is not my decision to make and more importantly I would not want to jump onto that unless that decision is made beforehand 😄
Solution
Anyways, since I still wanted to find some equivalent for
RestartableJenkinsRule
orJenkinsSessionRule
I opted for an extension toJenkinsRule
by providingJenkinsRule.restart()
. This method basically does the same as the JUnit4 rules but is agnostic to the JUnit version being used.Summed up shorty it creates a backup of the
JENKINS_HOME
and restarts the underlying Jenkins instance by runningJenkinsRule.after()
andJenkinsRule.before()
with the backup as home. The port remains unchanged.From what I can tell this method could be used in favor of
RestartableJenkinsRule
orJenkinsSessionRule
in most of the existing test cases:This would allow these projects to migrate to JUnit5 eventually without any downside and would open up the way to deprecate / discontinue the usage of JUnit4 in
jenkinsci
.@basil: FYI
Testing done
JenkinsRule.restart()
works for JUnit4 as well as JUnit5.JUnit5JenkinsRule
because I found them useful to have.Submitter checklist