blob: b95354f61d133379508e66f44fd80e2ca85a5eb9 [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.
Julia Kreger012c1c52015-04-21 20:11:39 -040081**ZUUL_CHANGES**
82 A caret character separated list of the changes upon which this build
83 is dependent upon in the form of a colon character separated list
84 consisting of project name, target branch, and revision ref.
James E. Blair81515ad2012-10-01 18:29:08 -070085**ZUUL_CHANGE_IDS**
86 All of the Gerrit change IDs that are included in this build (useful
Łukasz Jernaś048acb42014-03-02 18:49:41 +010087 when the DependentPipelineManager combines changes for testing).
James E. Blair81515ad2012-10-01 18:29:08 -070088**ZUUL_PATCHSET**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010089 The Gerrit patchset number for the change that triggered this build.
James E. Blaircdd00072012-06-08 19:17:28 -070090
Antoine Mussoe0f5bb42014-03-04 11:30:37 +010091Reference updated parameters
92~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93
James E. Blair1f4c2bb2013-04-26 08:40:46 -070094The following additional parameters will only be provided for
James E. Blair81515ad2012-10-01 18:29:08 -070095post-merge (ref-updated) builds:
James E. Blaircdd00072012-06-08 19:17:28 -070096
James E. Blair81515ad2012-10-01 18:29:08 -070097**ZUUL_OLDREV**
98 The SHA1 of the old revision at this ref (recall the ref name is
Łukasz Jernaś048acb42014-03-02 18:49:41 +010099 in ZUUL_REF).
James E. Blair81515ad2012-10-01 18:29:08 -0700100**ZUUL_NEWREV**
101 The SHA1 of the new revision at this ref (recall the ref name is
Łukasz Jernaś048acb42014-03-02 18:49:41 +0100102 in ZUUL_REF).
James E. Blair81515ad2012-10-01 18:29:08 -0700103**ZUUL_SHORT_OLDREV**
Łukasz Jernaś048acb42014-03-02 18:49:41 +0100104 The shortened (7 character) SHA1 of the old revision.
James E. Blair81515ad2012-10-01 18:29:08 -0700105**ZUUL_SHORT_NEWREV**
Łukasz Jernaś048acb42014-03-02 18:49:41 +0100106 The shortened (7 character) SHA1 of the new revision.
James E. Blaircdd00072012-06-08 19:17:28 -0700107
Antoine Mussoe0f5bb42014-03-04 11:30:37 +0100108Unset revisions default to 00000000000000000000000000000000.
109
110Examples:
111
112When a reference is created::
113
114 ZUUL_OLDREV=00000000000000000000000000000000
115 ZUUL_NEWREV=123456789abcdef123456789abcdef12
116 ZUUL_SHORT_OLDREV=0000000
117 ZUUL_SHORT_NEWREV=1234567
118
119When a reference is deleted::
120
121 ZUUL_OLDREV=123456789abcdef123456789abcdef12
122 ZUUL_NEWREV=00000000000000000000000000000000
123 ZUUL_SHORT_OLDREV=1234567
124 ZUUL_SHORT_NEWREV=0000000
125
126And finally a reference being altered::
127
128 ZUUL_OLDREV=123456789abcdef123456789abcdef12
129 ZUUL_NEWREV=abcdef123456789abcdef123456789ab
130 ZUUL_SHORT_OLDREV=1234567
131 ZUUL_SHORT_NEWREV=abcdef1
132
133Your jobs can check whether the parameters are ``000000`` to act
134differently on each kind of event.
135
Joshua Hesketh36c3fa52014-01-22 11:40:52 +1100136Swift parameters
137~~~~~~~~~~~~~~~~
138
139If swift information has been configured for the job zuul will also
140provide signed credentials for the builder to upload results and
141assets into containers using the `FormPost`_ middleware.
142
143Each zuul container/instruction set will contain each of the following
144parameters where $NAME is the ``name`` defined in the layout.
145
146*SWIFT_$NAME_URL*
147 The swift destination URL. This will be the entire URL including
148 the AUTH, container and path prefix (folder).
149*SWIFT_$NAME_HMAC_BODY*
150 The information signed in the HMAC body. The body is as follows::
151
152 PATH TO OBJECT PREFIX (excluding domain)
153 BLANK LINE (zuul implements no form redirect)
154 MAX FILE SIZE
155 MAX FILE COUNT
156 SIGNATURE EXPIRY
157
158*SWIFT_$NAME_SIGNATURE*
159 The HMAC body signed with the configured key.
160*SWIFT_$NAME_LOGSERVER_PREFIX*
161 The URL to prepend to the object path when returning the results
162 from a build.
163
Joshua Heskethe8987162014-03-13 13:05:33 +1100164Gearman
165-------
166
167Gearman_ is a general-purpose protocol for distributing jobs to any
168number of workers. Zuul works with Gearman by sending specific
169information with job requests to Gearman, and expects certain
170information to be returned on completion. This protocol is described
171in `Zuul-Gearman Protocol`_.
172
173In order for Zuul to run any jobs, you will need a running Gearman
174server. Zuul includes a Gearman server, and it is recommended that it
175be used as it supports the following features needed by Zuul:
176
177* Canceling jobs in the queue (admin protocol command "cancel job").
178* Strict FIFO queue operation (gearmand's round-robin mode may be
179 sufficient, but is untested).
180
181To enable the built-in server, see the ``gearman_server`` section of
182``zuul.conf``. Be sure that the host allows connections from Zuul and
183any workers (e.g., Jenkins masters) on TCP port 4730, and nowhere else
184(as the Gearman protocol does not include any provision for
185authentication).
186
187Gearman Jenkins Plugin
188~~~~~~~~~~~~~~~~~~~~~~
189
190The `Gearman Jenkins Plugin`_ makes it easy to use Jenkins with Zuul
191by providing an interface between Jenkins and Gearman. In this
192configuration, Zuul asks Gearman to run jobs, and Gearman can then
193distribute those jobs to any number of Jenkins systems (including
194multiple Jenkins masters).
195
196The `Gearman Plugin`_ can be installed in Jenkins in order to
197facilitate Jenkins running jobs for Zuul. Install the plugin and
198configure it with the hostname or IP address of your Gearman server
199and the port on which it is listening (4730 by default). It will
200automatically register all known Jenkins jobs as functions that Zuul
201can invoke via Gearman.
202
203Any number of masters can be configured in this way, and Gearman will
204distribute jobs to all of them as appropriate.
205
206No special Jenkins job configuration is needed to support triggering
207by Zuul.
208
209The Gearman Plugin will ensure the `Zuul Parameters`_ are supplied as
210Jenkins build parameters, so they will be available for use in the job
211configuration as well as to the running job as environment variables.
212
Antoine Mussoe0f5bb42014-03-04 11:30:37 +0100213Jenkins git plugin configuration
Joshua Heskethe8987162014-03-13 13:05:33 +1100214^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Antoine Mussoe0f5bb42014-03-04 11:30:37 +0100215
James E. Blair81515ad2012-10-01 18:29:08 -0700216In order to test the correct build, configure the Jenkins Git SCM
217plugin as follows::
James E. Blaircdd00072012-06-08 19:17:28 -0700218
James E. Blair81515ad2012-10-01 18:29:08 -0700219 Source Code Management:
220 Git
221 Repositories:
222 Repository URL: <your Gerrit or Zuul repository URL>
223 Advanced:
224 Refspec: ${ZUUL_REF}
225 Branches to build:
226 Branch Specifier: ${ZUUL_COMMIT}
James E. Blaire2819012013-06-28 17:17:26 -0400227 Advanced:
228 Clean after checkout: True
James E. Blaircdd00072012-06-08 19:17:28 -0700229
James E. Blair81515ad2012-10-01 18:29:08 -0700230That should be sufficient for a job that only builds a single project.
231If you have multiple interrelated projects (i.e., they share a Zuul
232Change Queue) that are built together, you may be able to configure
233the Git plugin to prepare them, or you may chose to use a shell script
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700234instead. As an example, the OpenStack project uses the following
235script to prepare the workspace for its integration testing:
James E. Blair81515ad2012-10-01 18:29:08 -0700236
K Jonathan Harker97e457e2013-02-26 13:29:38 -0800237 https://github.com/openstack-infra/devstack-gate/blob/master/devstack-vm-gate-wrap.sh
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700238
Joshua Hesketh6a0a6182014-03-13 13:23:30 +1100239Turbo Hipster Worker
240~~~~~~~~~~~~~~~~~~~~
241
242As an alternative to Jenkins, `Turbo-Hipster`_ is a small python
243project designed specifically as a zuul job worker which can be
244registered with gearman as a job runner. Please see the
245`Turbo-Hipster Documentation`_ for details on how to set it up.
246
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700247Zuul-Gearman Protocol
Joshua Heskethe8987162014-03-13 13:05:33 +1100248~~~~~~~~~~~~~~~~~~~~~
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700249
250This section is only relevant if you intend to implement a new kind of
251worker that runs jobs for Zuul via Gearman. If you just want to use
252Jenkins, see `Gearman Jenkins Plugin`_ instead.
253
254The Zuul protocol as used with Gearman is as follows:
255
256Starting Builds
Joshua Heskethe8987162014-03-13 13:05:33 +1100257^^^^^^^^^^^^^^^
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700258
259To start a build, Zuul invokes a Gearman function with the following
260format:
261
262 build:FUNCTION_NAME
263
264where **FUNCTION_NAME** is the name of the job that should be run. If
265the job should run on a specific node (or class of node), Zuul will
266instead invoke:
267
268 build:FUNCTION_NAME:NODE_NAME
269
270where **NODE_NAME** is the name or class of node on which the job
271should be run. This can be specified by setting the ZUUL_NODE
Antoine Musso7c5db972013-09-26 11:48:26 +0200272parameter in a parameter-function (see :ref:`includes` section in
273:ref:`zuulconf`).
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700274
275Zuul sends the ZUUL_* parameters described in `Zuul Parameters`_
276encoded in JSON format as the argument included with the
277SUBMIT_JOB_UNIQ request to Gearman. A unique ID (equal to the
278ZUUL_UUID parameter) is also supplied to Gearman, and is accessible as
279an added Gearman parameter with GRAB_JOB_UNIQ.
280
281When a Gearman worker starts running a job for Zuul, it should
282immediately send a WORK_DATA packet with the following information
283encoded in JSON format:
284
James E. Blair3c483cf2013-06-04 16:30:43 -0700285**name**
286 The name of the job.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700287
288**number**
289 The build number (unique to this job).
290
James E. Blair3c483cf2013-06-04 16:30:43 -0700291**manager**
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700292 A unique identifier associated with the Gearman worker that can
293 abort this build. See `Stopping Builds`_ for more information.
294
James E. Blair3c483cf2013-06-04 16:30:43 -0700295**url** (optional)
296 The URL with the status or results of the build. Will be used in
297 the status page and the final report.
298
Joshua Heskethba8776a2014-01-12 14:35:40 +0800299To help with debugging builds a worker may send back some optional
300metadata:
301
302**worker_name** (optional)
303 The name of the worker.
304
305**worker_hostname** (optional)
306 The hostname of the worker.
307
308**worker_ips** (optional)
309 A list of IPs for the worker.
310
311**worker_fqdn** (optional)
312 The FQDN of the worker.
313
314**worker_program** (optional)
315 The program name of the worker. For example Jenkins or turbo-hipster.
316
317**worker_version** (optional)
318 The version of the software running the job.
319
320**worker_extra** (optional)
321 A dictionary of any extra metadata you may want to pass along.
322
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700323It should then immediately send a WORK_STATUS packet with a value of 0
324percent complete. It may then optionally send subsequent WORK_STATUS
325packets with updated completion values.
326
327When the build is complete, it should send a final WORK_DATA packet
328with the following in JSON format:
329
330**result**
331 Either the string 'SUCCESS' if the job succeeded, or any other value
332 that describes the result if the job failed.
333
334Finally, it should send either a WORK_FAIL or WORK_COMPLETE packet as
335appropriate. A WORK_EXCEPTION packet will be interpreted as a
336WORK_FAIL, but the exception will be logged in Zuul's error log.
337
338Stopping Builds
Joshua Heskethe8987162014-03-13 13:05:33 +1100339^^^^^^^^^^^^^^^
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700340
341If Zuul needs to abort a build already in progress, it will invoke the
342following function through Gearman:
343
James E. Blair3c483cf2013-06-04 16:30:43 -0700344 stop:MANAGER_NAME
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700345
James E. Blair3c483cf2013-06-04 16:30:43 -0700346Where **MANAGER_NAME** is the name of the manager worker supplied in
347the initial WORK_DATA packet when the job started. This is used to
348direct the stop: function invocation to the correct Gearman worker
349that is capable of stopping that particular job. The argument to the
350function should be the following encoded in JSON format:
351
352**name**
353 The job name of the build to stop.
354
355**number**
356 The build number of the build to stop.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700357
358The original job is expected to complete with a WORK_DATA and
359WORK_FAIL packet as described in `Starting Builds`_.
360
361Build Descriptions
Joshua Heskethe8987162014-03-13 13:05:33 +1100362^^^^^^^^^^^^^^^^^^
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700363
364In order to update the job running system with a description of the
365current state of all related builds, the job runner may optionally
366implement the following Gearman function:
367
James E. Blair3c483cf2013-06-04 16:30:43 -0700368 set_description:MANAGER_NAME
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700369
James E. Blair3c483cf2013-06-04 16:30:43 -0700370Where **MANAGER_NAME** is used as described in `Stopping Builds`_.
371The argument to the function is the following encoded in JSON format:
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700372
James E. Blair3c483cf2013-06-04 16:30:43 -0700373**name**
374 The job name of the build to describe.
375
376**number**
377 The build number of the build to describe.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700378
379**html_description**
380 The description of the build in HTML format.