blob: 5f85f5828ca1a79859c93dc73ce112fe3131fb09 [file] [log] [blame]
Paul Belanger174a8272017-03-14 13:20:10 -04001:title: Executors
James E. Blaircdd00072012-06-08 19:17:28 -07002
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`:
Andreas Jaegere1ba7762016-06-03 15:08:25 +02009 https://git.openstack.org/cgit/openstack/turbo-hipster/
Joshua Hesketh6a0a6182014-03-13 13:23:30 +110010
11.. _`Turbo-Hipster Documentation`:
12 http://turbo-hipster.rtfd.org/
13
Paul Belanger174a8272017-03-14 13:20:10 -040014.. _executors:
Antoine Mussod06f2a62012-11-16 17:40:58 +010015
Paul Belanger174a8272017-03-14 13:20:10 -040016Executors
James E. Blaircdd00072012-06-08 19:17:28 -070017=========
18
Paul Belanger174a8272017-03-14 13:20:10 -040019Zuul has a modular architecture for executing jobs. Currently, the
James E. Blair1f4c2bb2013-04-26 08:40:46 -070020only supported module interfaces with Gearman_. This design allows
21any system to run jobs for Zuul simply by interfacing with a Gearman
22server. The recommended way of integrating a new job-runner with Zuul
23is via this method.
James E. Blaircdd00072012-06-08 19:17:28 -070024
Paul Belanger174a8272017-03-14 13:20:10 -040025If Gearman is unsuitable, Zuul may be extended with a new executor
James E. Blair1f4c2bb2013-04-26 08:40:46 -070026module. Zuul makes very few assumptions about the interface to a
Paul Belanger174a8272017-03-14 13:20:10 -040027executor -- if it can trigger jobs, cancel them, and receive success
James E. Blair1f4c2bb2013-04-26 08:40:46 -070028or failure reports, it should be able to be used with Zuul. Patches
29to this effect are welcome.
30
James E. Blair1f4c2bb2013-04-26 08:40:46 -070031Zuul Parameters
32---------------
James E. Blaircdd00072012-06-08 19:17:28 -070033
Paul Belanger174a8272017-03-14 13:20:10 -040034Zuul will pass some parameters with every job it executes. These are
Joshua Heskethe8987162014-03-13 13:05:33 +110035for workers to be able to get the repositories into the state they are
36intended to be tested in. Builds can be triggered either by an action
37on a change or by a reference update. Both events share a common set
38of parameters and more specific parameters as follows:
Antoine Mussoe0f5bb42014-03-04 11:30:37 +010039
40Common parameters
41~~~~~~~~~~~~~~~~~
James E. Blaircdd00072012-06-08 19:17:28 -070042
James E. Blair81515ad2012-10-01 18:29:08 -070043**ZUUL_UUID**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010044 Zuul provided key to link builds with Gerrit events.
James E. Blair81515ad2012-10-01 18:29:08 -070045**ZUUL_REF**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010046 Zuul provided ref that includes commit(s) to build.
James E. Blair81515ad2012-10-01 18:29:08 -070047**ZUUL_COMMIT**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010048 The commit SHA1 at the head of ZUUL_REF.
James E. Blair81515ad2012-10-01 18:29:08 -070049**ZUUL_PROJECT**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010050 The project that triggered this build.
James E. Blair81515ad2012-10-01 18:29:08 -070051**ZUUL_PIPELINE**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010052 The Zuul pipeline that is building this job.
Arx Cruzb1b010d2013-10-28 19:49:59 -020053**ZUUL_URL**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010054 The URL for the zuul server as configured in zuul.conf.
Joshua Heskethba8776a2014-01-12 14:35:40 +080055 A test runner may use this URL as the basis for fetching
Arx Cruzb1b010d2013-10-28 19:49:59 -020056 git commits.
Joshua Hesketh6c21dd12014-03-31 12:23:21 +110057**BASE_LOG_PATH**
58 zuul suggests a path to store and address logs. This is deterministic
59 and hence useful for where you want workers to upload to a specific
60 destination or need them to have a specific final URL you can link to
61 in advanced. For changes it is:
62 "last-two-digits-of-change/change-number/patchset-number".
63 For reference updates it is: "first-two-digits-of-newrev/newrev"
64**LOG_PATH**
65 zuul also suggests a unique path for logs to the worker. This is
66 "BASE_LOG_PATH/pipeline-name/job-name/uuid"
James E. Blair5821bd92015-09-16 08:48:15 -070067**ZUUL_VOTING**
68 Whether Zuul considers this job voting or not. Note that if Zuul is
69 reconfigured during the run, the voting status of a job may change
70 and this value will be out of date. Values are '1' if voting, '0'
71 otherwise.
James E. Blaircdd00072012-06-08 19:17:28 -070072
Antoine Mussoe0f5bb42014-03-04 11:30:37 +010073Change related parameters
74~~~~~~~~~~~~~~~~~~~~~~~~~
75
James E. Blair1f4c2bb2013-04-26 08:40:46 -070076The following additional parameters will only be provided for builds
77associated with changes (i.e., in response to patchset-created or
78comment-added events):
James E. Blaircdd00072012-06-08 19:17:28 -070079
James E. Blair81515ad2012-10-01 18:29:08 -070080**ZUUL_BRANCH**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010081 The target branch for the change that triggered this build.
James E. Blair81515ad2012-10-01 18:29:08 -070082**ZUUL_CHANGE**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010083 The Gerrit change ID for the change that triggered this build.
Julia Kreger012c1c52015-04-21 20:11:39 -040084**ZUUL_CHANGES**
85 A caret character separated list of the changes upon which this build
86 is dependent upon in the form of a colon character separated list
87 consisting of project name, target branch, and revision ref.
James E. Blair81515ad2012-10-01 18:29:08 -070088**ZUUL_CHANGE_IDS**
89 All of the Gerrit change IDs that are included in this build (useful
Łukasz Jernaś048acb42014-03-02 18:49:41 +010090 when the DependentPipelineManager combines changes for testing).
James E. Blair81515ad2012-10-01 18:29:08 -070091**ZUUL_PATCHSET**
Łukasz Jernaś048acb42014-03-02 18:49:41 +010092 The Gerrit patchset number for the change that triggered this build.
James E. Blaircdd00072012-06-08 19:17:28 -070093
Antoine Mussoe0f5bb42014-03-04 11:30:37 +010094Reference updated parameters
95~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96
James E. Blair1f4c2bb2013-04-26 08:40:46 -070097The following additional parameters will only be provided for
James E. Blair81515ad2012-10-01 18:29:08 -070098post-merge (ref-updated) builds:
James E. Blaircdd00072012-06-08 19:17:28 -070099
James E. Blair81515ad2012-10-01 18:29:08 -0700100**ZUUL_OLDREV**
101 The SHA1 of the old 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_NEWREV**
104 The SHA1 of the new revision at this ref (recall the ref name is
Łukasz Jernaś048acb42014-03-02 18:49:41 +0100105 in ZUUL_REF).
James E. Blair81515ad2012-10-01 18:29:08 -0700106**ZUUL_SHORT_OLDREV**
Łukasz Jernaś048acb42014-03-02 18:49:41 +0100107 The shortened (7 character) SHA1 of the old revision.
James E. Blair81515ad2012-10-01 18:29:08 -0700108**ZUUL_SHORT_NEWREV**
Łukasz Jernaś048acb42014-03-02 18:49:41 +0100109 The shortened (7 character) SHA1 of the new revision.
James E. Blaircdd00072012-06-08 19:17:28 -0700110
Antoine Mussoe0f5bb42014-03-04 11:30:37 +0100111Unset revisions default to 00000000000000000000000000000000.
112
113Examples:
114
115When a reference is created::
116
117 ZUUL_OLDREV=00000000000000000000000000000000
118 ZUUL_NEWREV=123456789abcdef123456789abcdef12
119 ZUUL_SHORT_OLDREV=0000000
120 ZUUL_SHORT_NEWREV=1234567
121
122When a reference is deleted::
123
124 ZUUL_OLDREV=123456789abcdef123456789abcdef12
125 ZUUL_NEWREV=00000000000000000000000000000000
126 ZUUL_SHORT_OLDREV=1234567
127 ZUUL_SHORT_NEWREV=0000000
128
129And finally a reference being altered::
130
131 ZUUL_OLDREV=123456789abcdef123456789abcdef12
132 ZUUL_NEWREV=abcdef123456789abcdef123456789ab
133 ZUUL_SHORT_OLDREV=1234567
134 ZUUL_SHORT_NEWREV=abcdef1
135
136Your jobs can check whether the parameters are ``000000`` to act
137differently on each kind of event.
138
Joshua Heskethe8987162014-03-13 13:05:33 +1100139Gearman
140-------
141
142Gearman_ is a general-purpose protocol for distributing jobs to any
143number of workers. Zuul works with Gearman by sending specific
144information with job requests to Gearman, and expects certain
145information to be returned on completion. This protocol is described
146in `Zuul-Gearman Protocol`_.
147
148In order for Zuul to run any jobs, you will need a running Gearman
149server. Zuul includes a Gearman server, and it is recommended that it
150be used as it supports the following features needed by Zuul:
151
152* Canceling jobs in the queue (admin protocol command "cancel job").
153* Strict FIFO queue operation (gearmand's round-robin mode may be
154 sufficient, but is untested).
155
156To enable the built-in server, see the ``gearman_server`` section of
157``zuul.conf``. Be sure that the host allows connections from Zuul and
158any workers (e.g., Jenkins masters) on TCP port 4730, and nowhere else
159(as the Gearman protocol does not include any provision for
160authentication).
161
162Gearman Jenkins Plugin
163~~~~~~~~~~~~~~~~~~~~~~
164
165The `Gearman Jenkins Plugin`_ makes it easy to use Jenkins with Zuul
166by providing an interface between Jenkins and Gearman. In this
167configuration, Zuul asks Gearman to run jobs, and Gearman can then
168distribute those jobs to any number of Jenkins systems (including
169multiple Jenkins masters).
170
171The `Gearman Plugin`_ can be installed in Jenkins in order to
172facilitate Jenkins running jobs for Zuul. Install the plugin and
173configure it with the hostname or IP address of your Gearman server
174and the port on which it is listening (4730 by default). It will
175automatically register all known Jenkins jobs as functions that Zuul
176can invoke via Gearman.
177
178Any number of masters can be configured in this way, and Gearman will
179distribute jobs to all of them as appropriate.
180
181No special Jenkins job configuration is needed to support triggering
182by Zuul.
183
184The Gearman Plugin will ensure the `Zuul Parameters`_ are supplied as
185Jenkins build parameters, so they will be available for use in the job
186configuration as well as to the running job as environment variables.
187
Antoine Mussoe0f5bb42014-03-04 11:30:37 +0100188Jenkins git plugin configuration
Joshua Heskethe8987162014-03-13 13:05:33 +1100189^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Antoine Mussoe0f5bb42014-03-04 11:30:37 +0100190
James E. Blair81515ad2012-10-01 18:29:08 -0700191In order to test the correct build, configure the Jenkins Git SCM
192plugin as follows::
James E. Blaircdd00072012-06-08 19:17:28 -0700193
James E. Blair81515ad2012-10-01 18:29:08 -0700194 Source Code Management:
195 Git
196 Repositories:
197 Repository URL: <your Gerrit or Zuul repository URL>
198 Advanced:
199 Refspec: ${ZUUL_REF}
200 Branches to build:
201 Branch Specifier: ${ZUUL_COMMIT}
James E. Blaire2819012013-06-28 17:17:26 -0400202 Advanced:
203 Clean after checkout: True
James E. Blaircdd00072012-06-08 19:17:28 -0700204
James E. Blair81515ad2012-10-01 18:29:08 -0700205That should be sufficient for a job that only builds a single project.
206If you have multiple interrelated projects (i.e., they share a Zuul
207Change Queue) that are built together, you may be able to configure
208the Git plugin to prepare them, or you may chose to use a shell script
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700209instead. As an example, the OpenStack project uses the following
210script to prepare the workspace for its integration testing:
James E. Blair81515ad2012-10-01 18:29:08 -0700211
Andreas Jaeger2055dcd2015-12-29 21:47:21 +0100212 https://git.openstack.org/cgit/openstack-infra/devstack-gate/tree/devstack-vm-gate-wrap.sh
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700213
Joshua Hesketh6a0a6182014-03-13 13:23:30 +1100214Turbo Hipster Worker
215~~~~~~~~~~~~~~~~~~~~
216
217As an alternative to Jenkins, `Turbo-Hipster`_ is a small python
218project designed specifically as a zuul job worker which can be
219registered with gearman as a job runner. Please see the
220`Turbo-Hipster Documentation`_ for details on how to set it up.
221
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700222Zuul-Gearman Protocol
Joshua Heskethe8987162014-03-13 13:05:33 +1100223~~~~~~~~~~~~~~~~~~~~~
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700224
225This section is only relevant if you intend to implement a new kind of
226worker that runs jobs for Zuul via Gearman. If you just want to use
227Jenkins, see `Gearman Jenkins Plugin`_ instead.
228
229The Zuul protocol as used with Gearman is as follows:
230
231Starting Builds
Joshua Heskethe8987162014-03-13 13:05:33 +1100232^^^^^^^^^^^^^^^
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700233
234To start a build, Zuul invokes a Gearman function with the following
235format:
236
237 build:FUNCTION_NAME
238
239where **FUNCTION_NAME** is the name of the job that should be run. If
240the job should run on a specific node (or class of node), Zuul will
241instead invoke:
242
243 build:FUNCTION_NAME:NODE_NAME
244
245where **NODE_NAME** is the name or class of node on which the job
Paul Belangerf36a4132016-11-07 16:37:00 -0500246should be run.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700247
248Zuul sends the ZUUL_* parameters described in `Zuul Parameters`_
249encoded in JSON format as the argument included with the
250SUBMIT_JOB_UNIQ request to Gearman. A unique ID (equal to the
251ZUUL_UUID parameter) is also supplied to Gearman, and is accessible as
252an added Gearman parameter with GRAB_JOB_UNIQ.
253
254When a Gearman worker starts running a job for Zuul, it should
255immediately send a WORK_DATA packet with the following information
256encoded in JSON format:
257
James E. Blair3c483cf2013-06-04 16:30:43 -0700258**name**
259 The name of the job.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700260
261**number**
262 The build number (unique to this job).
263
James E. Blair3c483cf2013-06-04 16:30:43 -0700264**manager**
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700265 A unique identifier associated with the Gearman worker that can
266 abort this build. See `Stopping Builds`_ for more information.
267
James E. Blair3c483cf2013-06-04 16:30:43 -0700268**url** (optional)
269 The URL with the status or results of the build. Will be used in
270 the status page and the final report.
271
Joshua Heskethba8776a2014-01-12 14:35:40 +0800272To help with debugging builds a worker may send back some optional
273metadata:
274
275**worker_name** (optional)
276 The name of the worker.
277
278**worker_hostname** (optional)
279 The hostname of the worker.
280
281**worker_ips** (optional)
282 A list of IPs for the worker.
283
284**worker_fqdn** (optional)
285 The FQDN of the worker.
286
287**worker_program** (optional)
288 The program name of the worker. For example Jenkins or turbo-hipster.
289
290**worker_version** (optional)
291 The version of the software running the job.
292
293**worker_extra** (optional)
294 A dictionary of any extra metadata you may want to pass along.
295
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700296It should then immediately send a WORK_STATUS packet with a value of 0
297percent complete. It may then optionally send subsequent WORK_STATUS
298packets with updated completion values.
299
300When the build is complete, it should send a final WORK_DATA packet
301with the following in JSON format:
302
303**result**
304 Either the string 'SUCCESS' if the job succeeded, or any other value
305 that describes the result if the job failed.
306
307Finally, it should send either a WORK_FAIL or WORK_COMPLETE packet as
308appropriate. A WORK_EXCEPTION packet will be interpreted as a
309WORK_FAIL, but the exception will be logged in Zuul's error log.
310
311Stopping Builds
Joshua Heskethe8987162014-03-13 13:05:33 +1100312^^^^^^^^^^^^^^^
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700313
314If Zuul needs to abort a build already in progress, it will invoke the
315following function through Gearman:
316
James E. Blair3c483cf2013-06-04 16:30:43 -0700317 stop:MANAGER_NAME
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700318
James E. Blair3c483cf2013-06-04 16:30:43 -0700319Where **MANAGER_NAME** is the name of the manager worker supplied in
320the initial WORK_DATA packet when the job started. This is used to
321direct the stop: function invocation to the correct Gearman worker
322that is capable of stopping that particular job. The argument to the
323function should be the following encoded in JSON format:
324
325**name**
326 The job name of the build to stop.
327
328**number**
329 The build number of the build to stop.
James E. Blair1f4c2bb2013-04-26 08:40:46 -0700330
331The original job is expected to complete with a WORK_DATA and
332WORK_FAIL packet as described in `Starting Builds`_.