Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Jenkins configuration for multiple environments

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?

like image 735
Alan Gerber Avatar asked Nov 09 '22 19:11

Alan Gerber


1 Answers

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.

like image 159
Walter A Avatar answered Nov 15 '22 05:11

Walter A