jenkins_job

jenkins_job is a cli tool that simplifies the management of Jenkins/Hudson jobs.

Most of my projects have more than one branch to keep tested. I prefer to have a Jenkins’ job per branch, instead of having a single job with multiple branches. This leads to have multiple similar jobs to maintain.

Common workflow

Make sure your job name contains a reference to the branch being tested, e.g.:

<project_name>_<branch_name>

Manage the project testing the master/trunk branch using the web interface. Then clone it and change the branch to be tested using the following command:

jenkins_job clone foo_master --original_branch master --new_branch production

The previous command uses the foo_master job as a reference and creates a new project named foo_production testing the production branch.

Note well: the command must be executed within the directory containing Jenkins’ jobs, which is <jenkins_home>/jobs.

You can also clone multiple projects at the same time:

jenkins_job clone foo_master bar_master --original_branch master --new_branch production

Taking advantage of shell globbing you can even do:

jenkins_job clone *_master --original_branch master --new_branch production

Other features

jenkins_job can help you in other ways.

Disable/enable projects

It’s possible to enable or disable multiple projects with a simple command:

jenkins_job enable|disable project1 project2 project3 ...

Thanks to bash file globbing you can change all the ‘master’ projects by typing:

jenkins_job enable|disable foo_*

Copy settings to other projects

Suppose you have configured irc notifications for one of your projects and you want to copy this configuration to other jobs.

Irc notification plugin saves its settings under the following xml node:

project/hudson.plugins.ircbot.IrcPublisher

Just execute this command:

jenkins_job copy_setting hudson.plugins.ircbot.IrcPublisher foo_master bar_master

Now the bar_master project will have the irc notifications turned on and configured like foo_master.

You can also copy a setting to multiple projects at the same time:

jenkins_job copy_setting hudson.plugins.ircbot.IrcPublisher foo_master foo_production bar_master

Taking advantage of shell globbing you can even do:

jenkins_job copy_setting hudson.plugins.ircbot.IrcPublisher foo_master bar*