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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With