blob: c79929129f25a0bac897eef5edbe05c2aac1e33a [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.
Joshua Hesketh6c21dd12014-03-31 12:23:21 +110059**BASE_LOG_PATH**
60 zuul suggests a path to store and address logs. This is deterministic
61 and hence useful for where you want workers to upload to a specific
62 destination or need them to have a specific final URL you can link to
63 in advanced. For changes it is:
64 "last-two-digits-of-change/change-number/patchset-number".
65 For reference updates it is: "first-two-digits-of-newrev/newrev"
66**LOG_PATH**
67 zuul also suggests a unique path for logs to the worker. This is
68 "BASE_LOG_PATH/pipeline-name/job-name/uuid"
James E. Blaircdd00072012-06-08 19:17:28 -070069
Antoine Mussoe0f5bb42014-03-04 11:30:37 +010070Change related parameters
71~~~~~~~~~~~~~~~~~~~~~~~~~
72
James E. Blair1f4c2bb2013-04-26 08:40:46 -070073The following additional parameters will only be provided for builds
74associated with changes (i.e., in response to patchset-created or
75comment-added events):
James E. Blaircdd00072012-06-08 19:17:28 -070076
James E. Blair81515ad2012-10-01 18:29:08 -070077**ZUUL_BRANCH**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010078 The target branch for the change that triggered this build.
James E. Blair81515ad2012-10-01 18:29:08 -070079**ZUUL_CHANGE**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010080 The Gerrit change ID for the change that triggered this build.
James E. Blair81515ad2012-10-01 18:29:08 -070081**ZUUL_CHANGE_IDS**
82 All of the Gerrit change IDs that are included in this build (useful
Łukasz Jernaś048acb42014-03-02 18:49:41 +010083 when the DependentPipelineManager combines changes for testing).
James E. Blair81515ad2012-10-01 18:29:08 -070084**ZUUL_PATCHSET**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010085 The Gerrit patchset number for the change that triggered this build.
James E. Blaircdd00072012-06-08 19:17:28 -070086
Antoine Mussoe0f5bb42014-03-04 11:30:37 +010087Reference updated parameters
88~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89
James E. Blair1f4c2bb2013-04-26 08:40:46 -070090The following additional parameters will only be provided for
James E. Blair81515ad2012-10-01 18:29:08 -070091post-merge (ref-updated) builds:
James E. Blaircdd00072012-06-08 19:17:28 -070092
James E. Blair81515ad2012-10-01 18:29:08 -070093**ZUUL_OLDREV**
94 The SHA1 of the old revision at this ref (recall the ref name is
Łukasz Jernaś048acb42014-03-02 18:49:41 +010095 in ZUUL_REF).
James E. Blair81515ad2012-10-01 18:29:08 -070096**ZUUL_NEWREV**
97 The SHA1 of the new revision at this ref (recall the ref name is
Łukasz Jernaś048acb42014-03-02 18:49:41 +010098 in ZUUL_REF).
James E. Blair81515ad2012-10-01 18:29:08 -070099**ZUUL_SHORT_OLDREV**
Łukasz Jernaś048acb42014-03-02 18:49:41 +0100100 The shortened (7 character) SHA1 of the old revision.
James E. Blair81515ad2012-10-01 18:29:08 -0700101**ZUUL_SHORT_NEWREV**
Łukasz Jernaś048acb42014-03-02 18:49:41 +0100102 The shortened (7 character) SHA1 of the new revision.
James E. Blaircdd00072012-06-08 19:17:28 -0700103
Antoine Mussoe0f5bb42014-03-04 11:30:37 +0100104Unset revisions default to 00000000000000000000000000000000.
105
106Examples:
107
108When a reference is created::
109
110 ZUUL_OLDREV=00000000000000000000000000000000
111 ZUUL_NEWREV=123456789abcdef123456789abcdef12
112 ZUUL_SHORT_OLDREV=0000000
113 ZUUL_SHORT_NEWREV=1234567
114
115When a reference is deleted::
116
117 ZUUL_OLDREV=123456789abcdef123456789abcdef12
118 ZUUL_NEWREV=00000000000000000000000000000000
119 ZUUL_SHORT_OLDREV=1234567
120 ZUUL_SHORT_NEWREV=0000000
121
122And finally a reference being altered::
123
124 ZUUL_OLDREV=123456789abcdef123456789abcdef12
125 ZUUL_NEWREV=abcdef123456789abcdef123456789ab
126 ZUUL_SHORT_OLDREV=1234567
127 ZUUL_SHORT_NEWREV=abcdef1
128
129Your jobs can check whether the parameters are ``000000`` to act
130differently on each kind of event.
131
Joshua Hesketh36c3fa52014-01-22 11:40:52 +1100132Swift parameters
133~~~~~~~~~~~~~~~~
134
135If swift information has been configured for the job zuul will also
136provide signed credentials for the builder to upload results and
137assets into containers using the `FormPost`_ middleware.
138
139Each zuul container/instruction set will contain each of the following
140parameters where $NAME is the ``name`` defined in the layout.
141
142*SWIFT_$NAME_URL*
143 The swift destination URL. This will be the entire URL including
144 the AUTH, container and path prefix (folder).
145*SWIFT_$NAME_HMAC_BODY*
146 The information signed in the HMAC body. The body is as follows::
147
148 PATH TO OBJECT PREFIX (excluding domain)
149 BLANK LINE (zuul implements no form redirect)
150 MAX FILE SIZE
151 MAX FILE COUNT
152 SIGNATURE EXPIRY
153
154*SWIFT_$NAME_SIGNATURE*
155 The HMAC body signed with the configured key.
156*SWIFT_$NAME_LOGSERVER_PREFIX*
157 The URL to prepend to the object path when returning the results
158 from a build.
159
Joshua Heskethe8987162014-03-13 13:05:33 +1100160Gearman
161-------
162
163Gearman_ is a general-purpose protocol for distributing jobs to any
164number of workers. Zuul works with Gearman by sending specific
165information with job requests to Gearman, and expects certain
166information to be returned on completion. This protocol is described
167in `Zuul-Gearman Protocol`_.
168
169In order for Zuul to run any jobs, you will need a running Gearman
170server. Zuul includes a Gearman server, and it is recommended that it
171be used as it supports the following features needed by Zuul:
172
173* Canceling jobs in the queue (admin protocol command "cancel job").
174* Strict FIFO queue operation (gearmand's round-robin mode may be
175 sufficient, but is untested).
176
177To enable the built-in server, see the ``gearman_server`` section of
178``zuul.conf``. Be sure that the host allows connections from Zuul and
179any workers (e.g., Jenkins masters) on TCP port 4730, and nowhere else
180(as the Gearman protocol does not include any provision for
181authentication).
182
183Gearman Jenkins Plugin
184~~~~~~~~~~~~~~~~~~~~~~
185
186The `Gearman Jenkins Plugin`_ makes it easy to use Jenkins with Zuul
187by providing an interface between Jenkins and Gearman. In this
188configuration, Zuul asks Gearman to run jobs, and Gearman can then
189distribute those jobs to any number of Jenkins systems (including
190multiple Jenkins masters).
191
192The `Gearman Plugin`_ can be installed in Jenkins in order to
193facilitate Jenkins running jobs for Zuul. Install the plugin and
194configure it with the hostname or IP address of your Gearman server
195and the port on which it is listening (4730 by default). It will
196automatically register all known Jenkins jobs as functions that Zuul
197can invoke via Gearman.
198
199Any number of masters can be configured in this way, and Gearman will
200distribute jobs to all of them as appropriate.
201
202No special Jenkins job configuration is needed to support triggering
203by Zuul.
204
205The Gearman Plugin will ensure the `Zuul Parameters`_ are supplied as
206Jenkins build parameters, so they will be available for use in the job
207configuration as well as to the running job as environment variables.
208
Antoine Mussoe0f5bb42014-03-04 11:30:37 +0100209Jenkins git plugin configuration
Joshua Heskethe8987162014-03-13 13:05:33 +1100210^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Antoine Mussoe0f5bb42014-03-04 11:30:37 +0100211
James E. Blair81515ad2012-10-01 18:29:08 -0700212In order to test the correct build, configure the Jenkins Git SCM
213plugin as follows::
James E. Blaircdd00072012-06-08 19:17:28 -0700214
James E. Blair81515ad2012-10-01 18:29:08 -0700215 Source Code Management:
216 Git
217 Repositories:
218 Repository URL: <your Gerrit or Zuul repository URL>
219 Advanced:
220 Refspec: ${ZUUL_REF}
221 Branches to build:
222 Branch Specifier: ${ZUUL_COMMIT}
James E. Blaire2819012013-06-28 17:17:26 -0400223 Advanced:
224 Clean after checkout: True
James E. Blaircdd00072012-06-08 19:17:28 -0700225
James E. Blair81515ad2012-10-01 18:29:08 -0700226That should be sufficient for a job that only builds a single project.
227If you have multiple interrelated projects (i.e., they share a Zuul
228Change Queue) that are built together, you may be able to configure
229the Git plugin to prepare them, or you may chose to use a shell script
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700230instead. As an example, the OpenStack project uses the following
231script to prepare the workspace for its integration testing:
James E. Blair81515ad2012-10-01 18:29:08 -0700232
K Jonathan Harker97e457e2013-02-26 13:29:38 -0800233 https://github.com/openstack-infra/devstack-gate/blob/master/devstack-vm-gate-wrap.sh
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700234
Joshua Hesketh6a0a6182014-03-13 13:23:30 +1100235Turbo Hipster Worker
236~~~~~~~~~~~~~~~~~~~~
237
238As an alternative to Jenkins, `Turbo-Hipster`_ is a small python
239project designed specifically as a zuul job worker which can be
240registered with gearman as a job runner. Please see the
241`Turbo-Hipster Documentation`_ for details on how to set it up.
242
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700243Zuul-Gearman Protocol
Joshua Heskethe8987162014-03-13 13:05:33 +1100244~~~~~~~~~~~~~~~~~~~~~
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700245
246This section is only relevant if you intend to implement a new kind of
247worker that runs jobs for Zuul via Gearman. If you just want to use
248Jenkins, see `Gearman Jenkins Plugin`_ instead.
249
250The Zuul protocol as used with Gearman is as follows:
251
252Starting Builds
Joshua Heskethe8987162014-03-13 13:05:33 +1100253^^^^^^^^^^^^^^^
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700254
255To start a build, Zuul invokes a Gearman function with the following
256format:
257
258 build:FUNCTION_NAME
259
260where **FUNCTION_NAME** is the name of the job that should be run. If
261the job should run on a specific node (or class of node), Zuul will
262instead invoke:
263
264 build:FUNCTION_NAME:NODE_NAME
265
266where **NODE_NAME** is the name or class of node on which the job
267should be run. This can be specified by setting the ZUUL_NODE
Antoine Musso7c5db972013-09-26 11:48:26 +0200268parameter in a parameter-function (see :ref:`includes` section in
269:ref:`zuulconf`).
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700270
271Zuul sends the ZUUL_* parameters described in `Zuul Parameters`_
272encoded in JSON format as the argument included with the
273SUBMIT_JOB_UNIQ request to Gearman. A unique ID (equal to the
274ZUUL_UUID parameter) is also supplied to Gearman, and is accessible as
275an added Gearman parameter with GRAB_JOB_UNIQ.
276
277When a Gearman worker starts running a job for Zuul, it should
278immediately send a WORK_DATA packet with the following information
279encoded in JSON format:
280
James E. Blair3c483cf2013-06-04 16:30:43 -0700281**name**
282 The name of the job.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700283
284**number**
285 The build number (unique to this job).
286
James E. Blair3c483cf2013-06-04 16:30:43 -0700287**manager**
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700288 A unique identifier associated with the Gearman worker that can
289 abort this build. See `Stopping Builds`_ for more information.
290
James E. Blair3c483cf2013-06-04 16:30:43 -0700291**url** (optional)
292 The URL with the status or results of the build. Will be used in
293 the status page and the final report.
294
Joshua Heskethba8776a2014-01-12 14:35:40 +0800295To help with debugging builds a worker may send back some optional
296metadata:
297
298**worker_name** (optional)
299 The name of the worker.
300
301**worker_hostname** (optional)
302 The hostname of the worker.
303
304**worker_ips** (optional)
305 A list of IPs for the worker.
306
307**worker_fqdn** (optional)
308 The FQDN of the worker.
309
310**worker_program** (optional)
311 The program name of the worker. For example Jenkins or turbo-hipster.
312
313**worker_version** (optional)
314 The version of the software running the job.
315
316**worker_extra** (optional)
317 A dictionary of any extra metadata you may want to pass along.
318
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700319It should then immediately send a WORK_STATUS packet with a value of 0
320percent complete. It may then optionally send subsequent WORK_STATUS
321packets with updated completion values.
322
323When the build is complete, it should send a final WORK_DATA packet
324with the following in JSON format:
325
326**result**
327 Either the string 'SUCCESS' if the job succeeded, or any other value
328 that describes the result if the job failed.
329
330Finally, it should send either a WORK_FAIL or WORK_COMPLETE packet as
331appropriate. A WORK_EXCEPTION packet will be interpreted as a
332WORK_FAIL, but the exception will be logged in Zuul's error log.
333
334Stopping Builds
Joshua Heskethe8987162014-03-13 13:05:33 +1100335^^^^^^^^^^^^^^^
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700336
337If Zuul needs to abort a build already in progress, it will invoke the
338following function through Gearman:
339
James E. Blair3c483cf2013-06-04 16:30:43 -0700340 stop:MANAGER_NAME
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700341
James E. Blair3c483cf2013-06-04 16:30:43 -0700342Where **MANAGER_NAME** is the name of the manager worker supplied in
343the initial WORK_DATA packet when the job started. This is used to
344direct the stop: function invocation to the correct Gearman worker
345that is capable of stopping that particular job. The argument to the
346function should be the following encoded in JSON format:
347
348**name**
349 The job name of the build to stop.
350
351**number**
352 The build number of the build to stop.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700353
354The original job is expected to complete with a WORK_DATA and
355WORK_FAIL packet as described in `Starting Builds`_.
356
357Build Descriptions
Joshua Heskethe8987162014-03-13 13:05:33 +1100358^^^^^^^^^^^^^^^^^^
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700359
360In order to update the job running system with a description of the
361current state of all related builds, the job runner may optionally
362implement the following Gearman function:
363
James E. Blair3c483cf2013-06-04 16:30:43 -0700364 set_description:MANAGER_NAME
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700365
James E. Blair3c483cf2013-06-04 16:30:43 -0700366Where **MANAGER_NAME** is used as described in `Stopping Builds`_.
367The argument to the function is the following encoded in JSON format:
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700368
James E. Blair3c483cf2013-06-04 16:30:43 -0700369**name**
370 The job name of the build to describe.
371
372**number**
373 The build number of the build to describe.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700374
375**html_description**
376 The description of the build in HTML format.