2013-05-24 23:56:35 +00:00
|
|
|
:title: Jenkins Job Builder
|
|
|
|
|
|
|
|
.. _jjb:
|
|
|
|
|
2012-05-15 21:21:49 +00:00
|
|
|
Jenkins Job Builder
|
2013-05-24 23:56:35 +00:00
|
|
|
###################
|
|
|
|
|
|
|
|
Jenkins Job Builder is a system for configuring Jenkins jobs using
|
|
|
|
simple YAML files stored in Git.
|
|
|
|
|
|
|
|
At a Glance
|
|
|
|
===========
|
|
|
|
|
|
|
|
:Hosts:
|
2016-06-15 20:42:23 +00:00
|
|
|
* http://zm*.openstack.org
|
2013-05-24 23:56:35 +00:00
|
|
|
:Configuration:
|
2014-09-20 02:28:44 +00:00
|
|
|
* :config:`jenkins/jobs/`
|
2013-05-24 23:56:35 +00:00
|
|
|
:Projects:
|
2013-07-22 04:08:11 +00:00
|
|
|
* https://git.openstack.org/cgit/openstack-infra/jenkins-job-builder
|
2013-05-24 23:56:35 +00:00
|
|
|
:Bugs:
|
2014-11-12 00:17:56 +00:00
|
|
|
* https://storyboard.openstack.org/#!/project/723
|
2013-05-24 23:56:35 +00:00
|
|
|
:Resources:
|
2015-05-14 21:38:19 +00:00
|
|
|
* `Reference Manual <http://docs.openstack.org/infra/jenkins-job-builder>`_
|
2012-05-15 21:21:49 +00:00
|
|
|
|
|
|
|
Overview
|
2013-05-24 23:56:35 +00:00
|
|
|
========
|
2012-05-15 21:21:49 +00:00
|
|
|
|
2014-09-20 02:28:44 +00:00
|
|
|
In order to make the process of managing thousands of Jenkins jobs
|
2013-05-24 23:56:35 +00:00
|
|
|
easier, Jenkins Job Builder was designed to take YAML based
|
|
|
|
configurations and convert those into jobs that are injected into
|
|
|
|
Jenkins.
|
2012-05-15 21:21:49 +00:00
|
|
|
|
2013-05-24 23:56:35 +00:00
|
|
|
The documentation below describes how the OpenStack Infrastructure
|
|
|
|
team uses the Jenkins Job Builder in our environment.
|
2012-09-20 19:11:13 +00:00
|
|
|
|
|
|
|
Configuring Projects
|
2013-05-24 23:56:35 +00:00
|
|
|
====================
|
2012-05-15 21:21:49 +00:00
|
|
|
|
2013-05-24 23:56:35 +00:00
|
|
|
The YAML scripts to make this work are stored in the
|
2014-09-20 02:28:44 +00:00
|
|
|
:config:`jenkins/jobs/` directory of the project-config repository.
|
|
|
|
In this directory you can have four different types of yaml config
|
|
|
|
files:
|
2012-09-20 19:11:13 +00:00
|
|
|
|
|
|
|
* Jenkins Jobs Defaults in ``defaults.yaml``.
|
|
|
|
* Jenkins Jobs Macros to give larger config sections meaningful names in
|
|
|
|
``macros.yaml``.
|
|
|
|
* Project specific configurations in ``project_name.yaml``.
|
2014-08-27 19:44:22 +00:00
|
|
|
* Job template configurations. Need a ``projects.yaml`` file to
|
|
|
|
specify how the templates should be filled out and templates go in
|
|
|
|
``template_name.yaml``.
|
2012-09-20 19:11:13 +00:00
|
|
|
|
|
|
|
YAML Format
|
2013-05-24 23:56:35 +00:00
|
|
|
===========
|
2012-09-20 19:11:13 +00:00
|
|
|
|
|
|
|
Defaults
|
2013-05-24 23:56:35 +00:00
|
|
|
--------
|
2012-05-15 21:21:49 +00:00
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
Example defaults config:
|
2012-05-15 21:21:49 +00:00
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
.. code-block:: yaml
|
2012-05-15 21:21:49 +00:00
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
- defaults:
|
|
|
|
name: global
|
|
|
|
project-type: freestyle
|
|
|
|
concurrent: true
|
2012-05-15 21:21:49 +00:00
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
wrappers:
|
|
|
|
- timeout:
|
|
|
|
timeout: 30
|
|
|
|
fail: true
|
|
|
|
- timestamps
|
|
|
|
|
|
|
|
logrotate:
|
|
|
|
daysToKeep: 1
|
|
|
|
numToKeep: -1
|
|
|
|
artifactDaysToKeep: -1
|
|
|
|
artifactNumToKeep: -1
|
|
|
|
|
|
|
|
This config starts with the ``- defaults::`` line. This specifies that this
|
|
|
|
section contains default values rather than job specifications. In this
|
|
|
|
section we specify a useful set of defaults including a default description
|
|
|
|
indicating Puppet manages these jobs, jobs are allowed to run concurrently,
|
|
|
|
and a thirty minute job timeout.
|
|
|
|
|
|
|
|
Macros
|
2013-05-24 23:56:35 +00:00
|
|
|
------
|
2012-09-20 19:11:13 +00:00
|
|
|
|
|
|
|
Macros exist to give meaningful names to blocks of configuration that can be
|
|
|
|
used in job configs in place of the blocks they name. For example:
|
2012-05-15 21:21:49 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
- builder:
|
|
|
|
name: git-prep
|
|
|
|
builders:
|
|
|
|
- shell: "/slave_scripts/git-prep.sh"
|
|
|
|
|
|
|
|
- builder:
|
|
|
|
name: docs
|
|
|
|
builders:
|
|
|
|
- shell: "/slave_scripts/run-docs.sh"
|
|
|
|
|
|
|
|
- publisher:
|
|
|
|
name: console-log
|
|
|
|
publishers:
|
|
|
|
- scp:
|
|
|
|
site: 'scp-server'
|
|
|
|
files:
|
|
|
|
- target: 'logs/$JOB_NAME/$BUILD_NUMBER'
|
|
|
|
copy-console: true
|
|
|
|
copy-after-failure: true
|
|
|
|
|
|
|
|
In this block of code we define two builder macros and one publisher macro.
|
|
|
|
Each macro has a name and using that name in a job config is equivalent to
|
|
|
|
having the yaml below the name in place of the name in the job config. The next
|
|
|
|
section shows how you can use these macros.
|
|
|
|
|
|
|
|
Job Config
|
2013-05-24 23:56:35 +00:00
|
|
|
----------
|
2012-09-20 19:11:13 +00:00
|
|
|
|
|
|
|
Example job config:
|
2012-05-28 15:44:33 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
- job:
|
|
|
|
name: example-docs
|
|
|
|
node: node-label
|
|
|
|
|
|
|
|
triggers:
|
|
|
|
- zuul
|
|
|
|
|
|
|
|
builders:
|
|
|
|
- git-prep
|
|
|
|
- docs
|
|
|
|
|
|
|
|
publishers:
|
|
|
|
- scp:
|
|
|
|
site: 'scp-server'
|
|
|
|
files:
|
|
|
|
- target: 'dir/ectory'
|
|
|
|
source: 'build/html/foo'
|
|
|
|
keep-hierarchy: true
|
|
|
|
- console-log
|
|
|
|
|
|
|
|
Each job specification begins with ``-job:``. Under this section you can
|
|
|
|
specify the job details like name, node, etc. Any detail defined in the
|
|
|
|
defaults section that is not defined under this job will be included as well.
|
|
|
|
In addition to attribute details you can also specify how jenkins should
|
|
|
|
perform this job. What trigger methods should be used, the build steps,
|
|
|
|
jenkins publishing steps and so on. The macros defined earlier make this easy
|
|
|
|
and simple.
|
|
|
|
|
|
|
|
Job Templates
|
2013-05-24 23:56:35 +00:00
|
|
|
-------------
|
2012-09-20 19:11:13 +00:00
|
|
|
|
|
|
|
Job templates allow you to specify a job config once with arguments that are
|
|
|
|
replaced with the values specified in ``projects.yaml``. This allows you to
|
|
|
|
reuse job configs across many projects. First you need a templated job config:
|
2012-05-28 15:44:33 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
- job-template:
|
|
|
|
name: '{name}-docs'
|
2012-05-28 15:44:33 +00:00
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
triggers:
|
|
|
|
- zuul
|
2012-05-28 15:44:33 +00:00
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
builders:
|
|
|
|
- git-prep
|
|
|
|
- docs
|
2012-05-28 15:44:33 +00:00
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
publishers:
|
|
|
|
- scp:
|
|
|
|
site: 'scp-server'
|
|
|
|
files:
|
|
|
|
- target: 'dir/ectory'
|
|
|
|
source: 'build/html/foo'
|
|
|
|
keep-hierarchy: true
|
|
|
|
- console-log
|
2012-05-28 15:44:33 +00:00
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
node: '{node}'
|
2012-05-28 15:44:33 +00:00
|
|
|
|
|
|
|
|
2012-09-20 19:11:13 +00:00
|
|
|
- job-group:
|
|
|
|
name: python-jobs
|
|
|
|
jobs:
|
|
|
|
- '{name}-docs'
|
|
|
|
|
|
|
|
This takes the previous ``example-docs`` job and templatizes it. This will
|
|
|
|
allow us to easily create ``example1-docs`` and ``example2-docs`` jobs.
|
|
|
|
Each job template begins with ``- job-template:`` and the job specification is
|
|
|
|
identical to the previous one, but we have introduced variable arguments. In
|
|
|
|
this case ``{name}`` is a variable value that will be replaced. The values for
|
|
|
|
name will be defined in the ``projects.yaml`` file.
|
|
|
|
|
|
|
|
The ``- job-group:`` section is not strictly necessary but allows you to group
|
|
|
|
many job templates with the same variable arguments under one name.
|
|
|
|
|
|
|
|
The ``projects.yaml`` pulls all of the magic together. It specifies the
|
2013-06-11 20:02:17 +00:00
|
|
|
arguments to and instantiates the job templates as real jobs. For example:
|
2012-09-20 19:11:13 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
- project:
|
|
|
|
name: example1
|
2014-06-19 19:46:08 +00:00
|
|
|
node: bare-trusty
|
2012-09-20 19:11:13 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
- python-jobs
|
|
|
|
|
|
|
|
- project:
|
|
|
|
name: example2
|
2014-02-14 22:37:59 +00:00
|
|
|
node: bare-centos6
|
2012-09-20 19:11:13 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
- {name}-docs
|
|
|
|
|
|
|
|
Each project using templated jobs should have its own ``- project:`` section.
|
|
|
|
Under this sections there should be a ``jobs:`` section with a list of job
|
|
|
|
templates or job groups to be used by this project. Other values under the
|
|
|
|
``- project:`` section define the arguments to the templates lised under
|
|
|
|
``jobs:``. In this case we are giving the docs template ``name`` and ``node``
|
|
|
|
values.
|
|
|
|
|
|
|
|
Notice that example1 makes use of the job group and example2 makes use of the
|
|
|
|
job template.
|
2012-05-28 15:44:33 +00:00
|
|
|
|
2016-06-15 20:42:23 +00:00
|
|
|
Zuul
|
|
|
|
====
|
2012-05-15 21:21:49 +00:00
|
|
|
|
2016-06-15 20:42:23 +00:00
|
|
|
In our environment, we no longer use Jenkins to execute jobs. Zuul
|
|
|
|
itself, via Ansible, runs the actual workload. Zuul reads JJB config
|
|
|
|
files in order to define its jobs, so, aside from the detail of not
|
|
|
|
actually using Jenkins or creating any jobs in it, the use of JJB to
|
|
|
|
configure jobs in Zuul is the same.
|