Reputation: 351
My company uses Jenkins as an integration test executor.
We have multiple instances for our production and staging environments. The different environment need Jenkins configurations that are very similar, but have slight variations in things like periodic execution, notification, job enablement and so on.
Currently, we store the Jenkins configuration XML in Git, and make per-environment modifications as part of our Chef recipe while redeploying instances.
However, this means that it is very difficult to update an instance's configuration without redeploying it.
Does anyone have a favorite mechanism for sharing Jenkins configuration across different instances while applying small modifications per-instance?
Upvotes: 5
Views: 1331
Reputation: 20002
You can make a multi-environment configfile with lines as
hostA:settings.xml:key_1:value_1A
hostB:settings.xml:key_1:value_1B
hostC:settings.xml:key_1:value_1C
hostD:settings.xml:key_1:value_1D
hostA:settings.xml:key_2:value_2A
hostB:settings.xml:key_2:value_2B
hostC:settings.xml:key_2:value_2C
hostD:settings.xml:key_2:value_2D
(above layout works when you do not need the : for key/values)
In your deployment script you call a post_configure script, that will select the correct host lines and replace the keys in the xml (keys found as <key>...</key>
).
The code of the post_configure can be written in different languages.
Example
When all targets are Linux, and the start- and end-tag for each value is one 1 line, I would use bash and code something like
grep $(hostname) multi.cfg | while IFS=: read host file key value; do
sed -i 's/'${key}'/'${value}'/g' ${file}
done
I believe this is a better approach than generating different distributions for the different systems.
Upvotes: 1
Reputation: 1324278
One possibility (not tested myself) would be to use the Jenkins Remote Access API through a wrapper like arangamani/jenkins_api_client
(ruby)
That would allow for updating jobs of remote Jenkins instance, modifying only the parameters for which you need a small variation.
Upvotes: 0
Reputation: 29821
I recently came across the gradle-jenkins-plugin which basically extends the Job DSL Plugin by allowing to maintain the job configurations in source control and apply them to a Jenkins server via Gradle. That way you can easily deploy the same configurations to different servers, with slight modifications using the DSL depending e.g. on the Jenkins server URL.
Alternatively, you could probably achieve something similar using the new Workflow Plugin.
Upvotes: 0