来自:http://techs.enovance.com/6006/manage-jenkins-jobs-with-yaml
You are here: Home ∼ Manage Jenkins Jobs with YAML
Manage Jenkins Jobs with YAML
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:
1
2
3
|
git clone https://github.com/openstack-infra/jenkins-job-builder
cd jenkins-job-builder
sudo python setup.py install
|
Configure /etc/jenkins_jobs/jenkins_jobs.ini file :
1
2
3
4
|
[jenkins]
user=USERNAME
password=PASSWORD
url=JENKINS_URL
|
Write now your own YAML file with the job decsription. Before pushing it into Jenkins you could test it by generate a XML file:
1
|
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:
1
|
jenkins-jobs --conf /etc/jenkins_jobs/jenkins_jobs.ini update my-job.yaml
|
Read the official documentation for more informations.
Job example
To picture you why it’s so simple to write a job in YAML, here is an example with eDeploy Unit tests:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
- job:
name: eDeploy-UnitTests-YAML
description: 'Do not edit this job through the web!'
project-type: freestyle
block-downstream: false
scm:
- git:
skip-tag: false
url: git@github.com:enovance/edeploy.git
triggers:
- pollscm: '@hourly'
builders:
- 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 . || :
publishers:
- warnings:
workspace-file-scanners:
- file-pattern: pyflakes.log
scanner: PyFlakes
- junit:
results: nosetests.xml
- sloccount:
pattern: sloccount.sc
- violations:
cpd:
pattern: output.xml
pylint:
pattern: pylint.log
- email:
recipients: devops@mycompany.com
|
Recent contributions
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.