The other day, I have spent a week on crafting a reusable JUnit rule to
complement JenkinsConfiguredWithCodeRule[2] that create Jenkins SUTs as
independent local processes. The use case here is starting Jenkins with
realistic classloading environment, testing realistic start/stop/restart
scenarios (otherwise affected by JUT) or setting up multiple Jenkinses
for test. I am distributing this to see if folks are interested in
having something like this available so we can extract it from the
plugin this was initially developed for.
---
The simplest way to consume it is:
```
public @Rule TemporaryFolder tmp = new TemporaryFolder();
public @Rule ExternalJenkinsRule ejr = new ExternalJenkinsRule(tmp);
@Test
@ExternalFixture(name = "my-jenkins", resource = "my-jenkins.yaml",
injectPlugins = "matrix-auth")
public void myJenkins() throws Exception {
ExternalJenkinsRule.Fixture myJenkins = ejr.fixture("my-jenkins");
com.offbytwo.jenkins.JenkinsServer jenkinsServer =
myJenkins.getClient();
...
}
```
- The Jenkinses are launched in parallel in case there are multiple of them.
- Injected plugins are inject with their dependencies resolved by
maven-hpi-plugin:resolve-test-dependencies (IOW, they have to be
declared as maven dependencies but their injections is safe and fast).
- Primary means of controlling such Jenkins is through
jenkinsci/java-client-api.
- Dedicated temporary folder is allocated for every Jenkins.
- Jenkins log can be accessed for investigation.
For advanced usage one can subclass the ExternalJenkinsRule (as
demonstrated by [1]) in order to:
- Rearrange or modify the declared fixture annotations per test (DRY).
- Alter plugins to inject (DRY).
- Specify particular environment variables, JVM or Jenkins arguments.
- All of the above can be tailored based on declared fixture role.
Meaning the customizations deployed to individual fixtures do not have
to be the same - common for heterogeneous grids.
There are certainly many areas to improve this, though for now my
question is: Does it sound useful to you?
[1] https://github.com/jenkinsci/node-sharing-plugin/pull/106
[2]
https://github.com/jenkinsci/configuration-as-code-plugin/blob/master/plugin/src/test/java/io/jenkins/plugins/casc/misc/JenkinsConfiguredWithCodeRule.java
Cheers
--
oliver
--
You received this message because you are subscribed to the Google Groups "Jenkins
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-dev/1be57933-62d2-7588-3e9e-83a4c7269b5d%40gmail.com.
For more options, visit https://groups.google.com/d/optout.