About Jenkins Job Builder
Jenkins jobs are stored in XML format on the Continuous Integration (CI) server which is not the best readable format to write a job manually. That’s why it’s highly preferable to manage jobs via graphic interface.
Jenkins Job Builder (JJB) is a software created by the OpenStack infra team which takes simple descriptions of Jenkins jobs in YAML format and uses them to configure Jenkins. That enables you to manage jobs in human readable text format and store them in a version control system. Also, JJB is able to configure remotly Jenkins with new jobs. By creating a template system, you can easily manage jobs with similar configurations. Also, you can store YAML files into your favorite CSV (called subversion control) to manage versionning on them.
How does it work ?
This is a conceptual picture of the workflow :
First of all, you need to install jenkins-job-builder:
git clone https://github.com/openstack-infra/jenkins-job-builder
sudo python setup.py install
Configure /etc/jenkins_jobs/jenkins_jobs.ini file :
Write now your own YAML file with the job decsription. Before pushing it into Jenkins you could test it by generate a XML file:
jenkins-jobs test my-job.yaml -o .
It’s actually useful if you want to convert current jobs into YAML format and check that XML output is what we have currently on Jenkins Server.
When you are ready, let’s go to update the job on our Jenkins server:
jenkins-jobs --conf /etc/jenkins_jobs/jenkins_jobs.ini update my-job.yaml
Read the official documentation for more informations.
To picture you why it’s so simple to write a job in YAML, here is an example with eDeploy Unit tests:
description: 'Do not edit this job through the web!'
- pollscm: '@hourly'
- shell: |
git clean -dxf
sloccount --duplicates --wide --details . | fgrep -v .svn > sloccount.sc || :
find . -name test\*.py|xargs nosetests --with-xunit --verbose || :
find . -name \*.py|egrep -v '^./tests/'|xargs pyflakes > pyflakes.log || :
rm -f pylint.log
for f in `find . -name \*.py|egrep -v '^./tests/'`; do
pylint --output-format=parseable --reports=y $f >> pylint.log
done || :
python /usr/local/lib/python2.7/dist-packages/clonedigger/clonedigger.py --cpd-output . || :
- file-pattern: pyflakes.log
To support more Jenkins plugins, we contributed some JJB publishers. These publishers translate YAML into XML for the following plugins:
- SLOCCount which generates the trend report for SLOCCount, an open source program which counts the number of lines of codes in over 25 different languages.
- Plot which provides generic plotting (or graphing) in Jenkins.
- IRCbot which enable Jenkins to send build notífications via IRC and lets you interact with Jenkins via an IRC bot.