blob: accd80b424c23a93284e2b813acba589ce8c3a43 [file] [log] [blame]
James E. Blaircdd00072012-06-08 19:17:28 -07001:title: Launchers
2
James E. Blair1f4c2bb2013-04-26 08:40:46 -07003.. _Gearman: http://gearman.org/
Antoine Mussod06f2a62012-11-16 17:40:58 +01004
James E. Blair1f4c2bb2013-04-26 08:40:46 -07005.. _`Gearman Plugin`:
6 https://wiki.jenkins-ci.org/display/JENKINS/Gearman+Plugin
7
Joshua Hesketh6a0a6182014-03-13 13:23:30 +11008.. _`Turbo-Hipster`:
9 http://git.openstack.org/cgit/stackforge/turbo-hipster/
10
11.. _`Turbo-Hipster Documentation`:
12 http://turbo-hipster.rtfd.org/
13
Joshua Hesketh36c3fa52014-01-22 11:40:52 +110014.. _FormPost: http://docs.openstack.org/developer/swift/misc.html#module-swift.common.middleware.formpost
15
James E. Blair1f4c2bb2013-04-26 08:40:46 -070016.. _launchers:
Antoine Mussod06f2a62012-11-16 17:40:58 +010017
James E. Blaircdd00072012-06-08 19:17:28 -070018Launchers
19=========
20
James E. Blair1f4c2bb2013-04-26 08:40:46 -070021Zuul has a modular architecture for launching jobs. Currently, the
22only supported module interfaces with Gearman_. This design allows
23any system to run jobs for Zuul simply by interfacing with a Gearman
24server. The recommended way of integrating a new job-runner with Zuul
25is via this method.
James E. Blaircdd00072012-06-08 19:17:28 -070026
James E. Blair1f4c2bb2013-04-26 08:40:46 -070027If Gearman is unsuitable, Zuul may be extended with a new launcher
28module. Zuul makes very few assumptions about the interface to a
29launcher -- if it can trigger jobs, cancel them, and receive success
30or failure reports, it should be able to be used with Zuul. Patches
31to this effect are welcome.
32
James E. Blair1f4c2bb2013-04-26 08:40:46 -070033Zuul Parameters
34---------------
James E. Blaircdd00072012-06-08 19:17:28 -070035
Joshua Heskethe8987162014-03-13 13:05:33 +110036Zuul will pass some parameters with every job it launches. These are
37for workers to be able to get the repositories into the state they are
38intended to be tested in. Builds can be triggered either by an action
39on a change or by a reference update. Both events share a common set
40of parameters and more specific parameters as follows:
Antoine Mussoe0f5bb42014-03-04 11:30:37 +010041
42Common parameters
43~~~~~~~~~~~~~~~~~
James E. Blaircdd00072012-06-08 19:17:28 -070044
James E. Blair81515ad2012-10-01 18:29:08 -070045**ZUUL_UUID**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010046 Zuul provided key to link builds with Gerrit events.
James E. Blair81515ad2012-10-01 18:29:08 -070047**ZUUL_REF**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010048 Zuul provided ref that includes commit(s) to build.
James E. Blair81515ad2012-10-01 18:29:08 -070049**ZUUL_COMMIT**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010050 The commit SHA1 at the head of ZUUL_REF.
James E. Blair81515ad2012-10-01 18:29:08 -070051**ZUUL_PROJECT**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010052 The project that triggered this build.
James E. Blair81515ad2012-10-01 18:29:08 -070053**ZUUL_PIPELINE**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010054 The Zuul pipeline that is building this job.
Arx Cruzb1b010d2013-10-28 19:49:59 -020055**ZUUL_URL**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010056 The URL for the zuul server as configured in zuul.conf.
Joshua Heskethba8776a2014-01-12 14:35:40 +080057 A test runner may use this URL as the basis for fetching
Arx Cruzb1b010d2013-10-28 19:49:59 -020058 git commits.
James E. Blaircdd00072012-06-08 19:17:28 -070059
Antoine Mussoe0f5bb42014-03-04 11:30:37 +010060Change related parameters
61~~~~~~~~~~~~~~~~~~~~~~~~~
62
James E. Blair1f4c2bb2013-04-26 08:40:46 -070063The following additional parameters will only be provided for builds
64associated with changes (i.e., in response to patchset-created or
65comment-added events):
James E. Blaircdd00072012-06-08 19:17:28 -070066
James E. Blair81515ad2012-10-01 18:29:08 -070067**ZUUL_BRANCH**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010068 The target branch for the change that triggered this build.
James E. Blair81515ad2012-10-01 18:29:08 -070069**ZUUL_CHANGE**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010070 The Gerrit change ID for the change that triggered this build.
James E. Blair81515ad2012-10-01 18:29:08 -070071**ZUUL_CHANGE_IDS**
72 All of the Gerrit change IDs that are included in this build (useful
Łukasz Jernaś048acb42014-03-02 18:49:41 +010073 when the DependentPipelineManager combines changes for testing).
James E. Blair81515ad2012-10-01 18:29:08 -070074**ZUUL_PATCHSET**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010075 The Gerrit patchset number for the change that triggered this build.
James E. Blaircdd00072012-06-08 19:17:28 -070076
Antoine Mussoe0f5bb42014-03-04 11:30:37 +010077Reference updated parameters
78~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79
James E. Blair1f4c2bb2013-04-26 08:40:46 -070080The following additional parameters will only be provided for
James E. Blair81515ad2012-10-01 18:29:08 -070081post-merge (ref-updated) builds:
James E. Blaircdd00072012-06-08 19:17:28 -070082
James E. Blair81515ad2012-10-01 18:29:08 -070083**ZUUL_OLDREV**
84 The SHA1 of the old revision at this ref (recall the ref name is
Łukasz Jernaś048acb42014-03-02 18:49:41 +010085 in ZUUL_REF).
James E. Blair81515ad2012-10-01 18:29:08 -070086**ZUUL_NEWREV**
87 The SHA1 of the new revision at this ref (recall the ref name is
Łukasz Jernaś048acb42014-03-02 18:49:41 +010088 in ZUUL_REF).
James E. Blair81515ad2012-10-01 18:29:08 -070089**ZUUL_SHORT_OLDREV**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010090 The shortened (7 character) SHA1 of the old revision.
James E. Blair81515ad2012-10-01 18:29:08 -070091**ZUUL_SHORT_NEWREV**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010092 The shortened (7 character) SHA1 of the new revision.
James E. Blaircdd00072012-06-08 19:17:28 -070093
Antoine Mussoe0f5bb42014-03-04 11:30:37 +010094Unset revisions default to 00000000000000000000000000000000.
95
96Examples:
97
98When a reference is created::
99
100 ZUUL_OLDREV=00000000000000000000000000000000
101 ZUUL_NEWREV=123456789abcdef123456789abcdef12
102 ZUUL_SHORT_OLDREV=0000000
103 ZUUL_SHORT_NEWREV=1234567
104
105When a reference is deleted::
106
107 ZUUL_OLDREV=123456789abcdef123456789abcdef12
108 ZUUL_NEWREV=00000000000000000000000000000000
109 ZUUL_SHORT_OLDREV=1234567
110 ZUUL_SHORT_NEWREV=0000000
111
112And finally a reference being altered::
113
114 ZUUL_OLDREV=123456789abcdef123456789abcdef12
115 ZUUL_NEWREV=abcdef123456789abcdef123456789ab
116 ZUUL_SHORT_OLDREV=1234567
117 ZUUL_SHORT_NEWREV=abcdef1
118
119Your jobs can check whether the parameters are ``000000`` to act
120differently on each kind of event.
121
Joshua Hesketh36c3fa52014-01-22 11:40:52 +1100122Swift parameters
123~~~~~~~~~~~~~~~~
124
125If swift information has been configured for the job zuul will also
126provide signed credentials for the builder to upload results and
127assets into containers using the `FormPost`_ middleware.
128
129Each zuul container/instruction set will contain each of the following
130parameters where $NAME is the ``name`` defined in the layout.
131
132*SWIFT_$NAME_URL*
133 The swift destination URL. This will be the entire URL including
134 the AUTH, container and path prefix (folder).
135*SWIFT_$NAME_HMAC_BODY*
136 The information signed in the HMAC body. The body is as follows::
137
138 PATH TO OBJECT PREFIX (excluding domain)
139 BLANK LINE (zuul implements no form redirect)
140 MAX FILE SIZE
141 MAX FILE COUNT
142 SIGNATURE EXPIRY
143
144*SWIFT_$NAME_SIGNATURE*
145 The HMAC body signed with the configured key.
146*SWIFT_$NAME_LOGSERVER_PREFIX*
147 The URL to prepend to the object path when returning the results
148 from a build.
149
Joshua Heskethe8987162014-03-13 13:05:33 +1100150Gearman
151-------
152
153Gearman_ is a general-purpose protocol for distributing jobs to any
154number of workers. Zuul works with Gearman by sending specific
155information with job requests to Gearman, and expects certain
156information to be returned on completion. This protocol is described
157in `Zuul-Gearman Protocol`_.
158
159In order for Zuul to run any jobs, you will need a running Gearman
160server. Zuul includes a Gearman server, and it is recommended that it
161be used as it supports the following features needed by Zuul:
162
163* Canceling jobs in the queue (admin protocol command "cancel job").
164* Strict FIFO queue operation (gearmand's round-robin mode may be
165 sufficient, but is untested).
166
167To enable the built-in server, see the ``gearman_server`` section of
168``zuul.conf``. Be sure that the host allows connections from Zuul and
169any workers (e.g., Jenkins masters) on TCP port 4730, and nowhere else
170(as the Gearman protocol does not include any provision for
171authentication).
172
173Gearman Jenkins Plugin
174~~~~~~~~~~~~~~~~~~~~~~
175
176The `Gearman Jenkins Plugin`_ makes it easy to use Jenkins with Zuul
177by providing an interface between Jenkins and Gearman. In this
178configuration, Zuul asks Gearman to run jobs, and Gearman can then
179distribute those jobs to any number of Jenkins systems (including
180multiple Jenkins masters).
181
182The `Gearman Plugin`_ can be installed in Jenkins in order to
183facilitate Jenkins running jobs for Zuul. Install the plugin and
184configure it with the hostname or IP address of your Gearman server
185and the port on which it is listening (4730 by default). It will
186automatically register all known Jenkins jobs as functions that Zuul
187can invoke via Gearman.
188
189Any number of masters can be configured in this way, and Gearman will
190distribute jobs to all of them as appropriate.
191
192No special Jenkins job configuration is needed to support triggering
193by Zuul.
194
195The Gearman Plugin will ensure the `Zuul Parameters`_ are supplied as
196Jenkins build parameters, so they will be available for use in the job
197configuration as well as to the running job as environment variables.
198
Antoine Mussoe0f5bb42014-03-04 11:30:37 +0100199Jenkins git plugin configuration
Joshua Heskethe8987162014-03-13 13:05:33 +1100200^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Antoine Mussoe0f5bb42014-03-04 11:30:37 +0100201
James E. Blair81515ad2012-10-01 18:29:08 -0700202In order to test the correct build, configure the Jenkins Git SCM
203plugin as follows::
James E. Blaircdd00072012-06-08 19:17:28 -0700204
James E. Blair81515ad2012-10-01 18:29:08 -0700205 Source Code Management:
206 Git
207 Repositories:
208 Repository URL: <your Gerrit or Zuul repository URL>
209 Advanced:
210 Refspec: ${ZUUL_REF}
211 Branches to build:
212 Branch Specifier: ${ZUUL_COMMIT}
James E. Blaire2819012013-06-28 17:17:26 -0400213 Advanced:
214 Clean after checkout: True
James E. Blaircdd00072012-06-08 19:17:28 -0700215
James E. Blair81515ad2012-10-01 18:29:08 -0700216That should be sufficient for a job that only builds a single project.
217If you have multiple interrelated projects (i.e., they share a Zuul
218Change Queue) that are built together, you may be able to configure
219the Git plugin to prepare them, or you may chose to use a shell script
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700220instead. As an example, the OpenStack project uses the following
221script to prepare the workspace for its integration testing:
James E. Blair81515ad2012-10-01 18:29:08 -0700222
K Jonathan Harker97e457e2013-02-26 13:29:38 -0800223 https://github.com/openstack-infra/devstack-gate/blob/master/devstack-vm-gate-wrap.sh
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700224
Joshua Hesketh6a0a6182014-03-13 13:23:30 +1100225Turbo Hipster Worker
226~~~~~~~~~~~~~~~~~~~~
227
228As an alternative to Jenkins, `Turbo-Hipster`_ is a small python
229project designed specifically as a zuul job worker which can be
230registered with gearman as a job runner. Please see the
231`Turbo-Hipster Documentation`_ for details on how to set it up.
232
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700233Zuul-Gearman Protocol
Joshua Heskethe8987162014-03-13 13:05:33 +1100234~~~~~~~~~~~~~~~~~~~~~
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700235
236This section is only relevant if you intend to implement a new kind of
237worker that runs jobs for Zuul via Gearman. If you just want to use
238Jenkins, see `Gearman Jenkins Plugin`_ instead.
239
240The Zuul protocol as used with Gearman is as follows:
241
242Starting Builds
Joshua Heskethe8987162014-03-13 13:05:33 +1100243^^^^^^^^^^^^^^^
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700244
245To start a build, Zuul invokes a Gearman function with the following
246format:
247
248 build:FUNCTION_NAME
249
250where **FUNCTION_NAME** is the name of the job that should be run. If
251the job should run on a specific node (or class of node), Zuul will
252instead invoke:
253
254 build:FUNCTION_NAME:NODE_NAME
255
256where **NODE_NAME** is the name or class of node on which the job
257should be run. This can be specified by setting the ZUUL_NODE
Antoine Musso7c5db972013-09-26 11:48:26 +0200258parameter in a parameter-function (see :ref:`includes` section in
259:ref:`zuulconf`).
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700260
261Zuul sends the ZUUL_* parameters described in `Zuul Parameters`_
262encoded in JSON format as the argument included with the
263SUBMIT_JOB_UNIQ request to Gearman. A unique ID (equal to the
264ZUUL_UUID parameter) is also supplied to Gearman, and is accessible as
265an added Gearman parameter with GRAB_JOB_UNIQ.
266
267When a Gearman worker starts running a job for Zuul, it should
268immediately send a WORK_DATA packet with the following information
269encoded in JSON format:
270
James E. Blair3c483cf2013-06-04 16:30:43 -0700271**name**
272 The name of the job.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700273
274**number**
275 The build number (unique to this job).
276
James E. Blair3c483cf2013-06-04 16:30:43 -0700277**manager**
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700278 A unique identifier associated with the Gearman worker that can
279 abort this build. See `Stopping Builds`_ for more information.
280
James E. Blair3c483cf2013-06-04 16:30:43 -0700281**url** (optional)
282 The URL with the status or results of the build. Will be used in
283 the status page and the final report.
284
Joshua Heskethba8776a2014-01-12 14:35:40 +0800285To help with debugging builds a worker may send back some optional
286metadata:
287
288**worker_name** (optional)
289 The name of the worker.
290
291**worker_hostname** (optional)
292 The hostname of the worker.
293
294**worker_ips** (optional)
295 A list of IPs for the worker.
296
297**worker_fqdn** (optional)
298 The FQDN of the worker.
299
300**worker_program** (optional)
301 The program name of the worker. For example Jenkins or turbo-hipster.
302
303**worker_version** (optional)
304 The version of the software running the job.
305
306**worker_extra** (optional)
307 A dictionary of any extra metadata you may want to pass along.
308
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700309It should then immediately send a WORK_STATUS packet with a value of 0
310percent complete. It may then optionally send subsequent WORK_STATUS
311packets with updated completion values.
312
313When the build is complete, it should send a final WORK_DATA packet
314with the following in JSON format:
315
316**result**
317 Either the string 'SUCCESS' if the job succeeded, or any other value
318 that describes the result if the job failed.
319
320Finally, it should send either a WORK_FAIL or WORK_COMPLETE packet as
321appropriate. A WORK_EXCEPTION packet will be interpreted as a
322WORK_FAIL, but the exception will be logged in Zuul's error log.
323
324Stopping Builds
Joshua Heskethe8987162014-03-13 13:05:33 +1100325^^^^^^^^^^^^^^^
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700326
327If Zuul needs to abort a build already in progress, it will invoke the
328following function through Gearman:
329
James E. Blair3c483cf2013-06-04 16:30:43 -0700330 stop:MANAGER_NAME
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700331
James E. Blair3c483cf2013-06-04 16:30:43 -0700332Where **MANAGER_NAME** is the name of the manager worker supplied in
333the initial WORK_DATA packet when the job started. This is used to
334direct the stop: function invocation to the correct Gearman worker
335that is capable of stopping that particular job. The argument to the
336function should be the following encoded in JSON format:
337
338**name**
339 The job name of the build to stop.
340
341**number**
342 The build number of the build to stop.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700343
344The original job is expected to complete with a WORK_DATA and
345WORK_FAIL packet as described in `Starting Builds`_.
346
347Build Descriptions
Joshua Heskethe8987162014-03-13 13:05:33 +1100348^^^^^^^^^^^^^^^^^^
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700349
350In order to update the job running system with a description of the
351current state of all related builds, the job runner may optionally
352implement the following Gearman function:
353
James E. Blair3c483cf2013-06-04 16:30:43 -0700354 set_description:MANAGER_NAME
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700355
James E. Blair3c483cf2013-06-04 16:30:43 -0700356Where **MANAGER_NAME** is used as described in `Stopping Builds`_.
357The argument to the function is the following encoded in JSON format:
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700358
James E. Blair3c483cf2013-06-04 16:30:43 -0700359**name**
360 The job name of the build to describe.
361
362**number**
363 The build number of the build to describe.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700364
365**html_description**
366 The description of the build in HTML format.