blob: 2084c9c1c59ce603d2ee762ab6eae434d8c629d4 [file] [log] [blame]
James E. Blair1de8d402017-05-07 17:08:04 -07001:title: Project Configuration
2
3.. _project-config:
4
5Project Configuration
6=====================
7
8The following sections describe the main part of Zuul's configuration.
9All of what follows is found within files inside of the repositories
10that Zuul manages.
11
12Security Contexts
13-----------------
14
15When a system administrator configures Zuul to operate on a project,
16they specify one of two security contexts for that project. A
17*config-project* is one which is primarily tasked with holding
18configuration information and job content for Zuul. Jobs which are
19defined in a *config-project* are run with elevated privileges, and
20all Zuul configuration items are available for use. It is expected
21that changes to *config-projects* will undergo careful scrutiny before
22being merged.
23
24An *untrusted-project* is a project whose primary focus is not to
25operate Zuul, but rather it is one of the projects being tested or
26deployed. The Zuul configuration language available to these projects
27is somewhat restricted (as detailed in individual section below), and
28jobs defined in these projects run in a restricted execution
29environment since they may be operating on changes which have not yet
30undergone review.
31
32Configuration Loading
33---------------------
34
35When Zuul starts, it examines all of the git repositories which are
James E. Blaireff5a9d2017-06-20 00:00:37 -070036specified by the system administrator in :ref:`tenant-config` and searches
Tristan Cacqueray4a015832017-07-11 05:18:14 +000037for files in the root of each repository. Zuul looks first for a file named
38`zuul.yaml` or a directory named `zuul.d`, and if they are not found,
39`.zuul.yaml` or `.zuul.d` (with a leading dot). In the case of an
40*untrusted-project*, the configuration from every branch is included,
41however, in the case of a *config-project*, only the `master` branch is
42examined.
James E. Blair1de8d402017-05-07 17:08:04 -070043
44When a change is proposed to one of these files in an
45*untrusted-project*, the configuration proposed in the change is
46merged into the running configuration so that any changes to Zuul's
47configuration are self-testing as part of that change. If there is a
48configuration error, no jobs will be run and the error will be
49reported by any applicable pipelines. In the case of a change to a
50*config-project*, the new configuration is parsed and examined for
51errors, but the new configuration is not used in testing the change.
52This is because configuration in *config-projects* is able to access
53elevated privileges and should always be reviewed before being merged.
54
55As soon as a change containing a Zuul configuration change merges to
56any Zuul-managed repository, the new configuration takes effect
57immediately.
58
59Configuration Items
60-------------------
61
62The `zuul.yaml` and `.zuul.yaml` configuration files are
63YAML-formatted and are structured as a series of items, each of which
64is described below.
65
Tristan Cacqueray4a015832017-07-11 05:18:14 +000066In the case of a `zuul.d` directory, Zuul recurses the directory and extends
67the configuration using all the .yaml files in the sorted path order.
68For example, to keep job's variants in a separate file, it needs to be loaded
69after the main entries, for example using number prefixes in file's names::
70
71* zuul.d/pipelines.yaml
72* zuul.d/projects.yaml
73* zuul.d/01_jobs.yaml
74* zuul.d/02_jobs-variants.yaml
75
James E. Blair1de8d402017-05-07 17:08:04 -070076.. _pipeline:
77
78Pipeline
79~~~~~~~~
80
81A pipeline describes a workflow operation in Zuul. It associates jobs
82for a given project with triggering and reporting events.
83
84Its flexible configuration allows for characterizing any number of
85workflows, and by specifying each as a named configuration, makes it
86easy to apply similar workflow operations to projects or groups of
87projects.
88
89By way of example, one of the primary uses of Zuul is to perform
90project gating. To do so, one can create a *gate* pipeline which
91tells Zuul that when a certain event (such as approval by a code
92reviewer) occurs, the corresponding change or pull request should be
93enqueued into the pipeline. When that happens, the jobs which have
94been configured to run for that project in the *gate* pipeline are
95run, and when they complete, the pipeline reports the results to the
96user.
97
98Pipeline configuration items may only appear in *config-projects*.
99
100Generally, a Zuul administrator would define a small number of
101pipelines which represent the workflow processes used in their
102environment. Each project can then be added to the available
103pipelines as appropriate.
104
105Here is an example *check* pipeline, which runs whenever a new
106patchset is created in Gerrit. If the associated jobs all report
107success, the pipeline reports back to Gerrit with a *Verified* vote of
108+1, or if at least one of them fails, a -1::
109
110 - pipeline:
James E. Blaira8387ec2017-07-05 14:00:12 -0700111 name: check
James E. Blair1de8d402017-05-07 17:08:04 -0700112 manager: independent
113 trigger:
114 my_gerrit:
115 - event: patchset-created
116 success:
117 my_gerrit:
Tobias Henkelea98a192017-05-29 21:15:17 +0200118 Verified: 1
James E. Blair1de8d402017-05-07 17:08:04 -0700119 failure:
120 my_gerrit
Tobias Henkelea98a192017-05-29 21:15:17 +0200121 Verified: -1
James E. Blair1de8d402017-05-07 17:08:04 -0700122
James E. Blaireff5a9d2017-06-20 00:00:37 -0700123.. TODO: See TODO for more annotated examples of common pipeline configurations.
James E. Blair1de8d402017-05-07 17:08:04 -0700124
James E. Blair7145c582017-07-26 13:30:39 -0700125.. zuul:configobject:: pipeline
126
James E. Blair9fd98ab2017-07-26 14:15:26 -0700127 The attributes available on a pipeline are as follows (all are
128 optional unless otherwise specified):
James E. Blair1de8d402017-05-07 17:08:04 -0700129
James E. Blair9fd98ab2017-07-26 14:15:26 -0700130 .. zuul:attr:: name
131 :required:
James E. Blair1de8d402017-05-07 17:08:04 -0700132
James E. Blair9fd98ab2017-07-26 14:15:26 -0700133 This is used later in the project definition to indicate what jobs
134 should be run for events in the pipeline.
James E. Blair1de8d402017-05-07 17:08:04 -0700135
James E. Blair9fd98ab2017-07-26 14:15:26 -0700136 .. zuul:attr:: manager
137 :required:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700138
James E. Blair9fd98ab2017-07-26 14:15:26 -0700139 There are currently two schemes for managing pipelines:
James E. Blair1de8d402017-05-07 17:08:04 -0700140
James E. Blair9fd98ab2017-07-26 14:15:26 -0700141 .. _independent_pipeline_manager:
James E. Blair1de8d402017-05-07 17:08:04 -0700142
James E. Blair9fd98ab2017-07-26 14:15:26 -0700143 .. zuul:value:: independent
James E. Blaireff5a9d2017-06-20 00:00:37 -0700144
James E. Blair9fd98ab2017-07-26 14:15:26 -0700145 Every event in this pipeline should be treated as independent
146 of other events in the pipeline. This is appropriate when
147 the order of events in the pipeline doesn't matter because
148 the results of the actions this pipeline performs can not
149 affect other events in the pipeline. For example, when a
150 change is first uploaded for review, you may want to run
151 tests on that change to provide early feedback to reviewers.
152 At the end of the tests, the change is not going to be
153 merged, so it is safe to run these tests in parallel without
154 regard to any other changes in the pipeline. They are
155 independent.
James E. Blair1de8d402017-05-07 17:08:04 -0700156
James E. Blair9fd98ab2017-07-26 14:15:26 -0700157 Another type of pipeline that is independent is a post-merge
158 pipeline. In that case, the changes have already merged, so
159 the results can not affect any other events in the pipeline.
James E. Blair1761e862017-07-25 16:15:47 -0700160
James E. Blair9fd98ab2017-07-26 14:15:26 -0700161 .. _dependent_pipeline_manager:
James E. Blair1761e862017-07-25 16:15:47 -0700162
James E. Blair9fd98ab2017-07-26 14:15:26 -0700163 .. zuul:value:: dependent
James E. Blair1761e862017-07-25 16:15:47 -0700164
James E. Blair9fd98ab2017-07-26 14:15:26 -0700165 The dependent pipeline manager is designed for gating. It
166 ensures that every change is tested exactly as it is going to
167 be merged into the repository. An ideal gating system would
168 test one change at a time, applied to the tip of the
169 repository, and only if that change passed tests would it be
170 merged. Then the next change in line would be tested the
171 same way. In order to achieve parallel testing of changes,
172 the dependent pipeline manager performs speculative execution
173 on changes. It orders changes based on their entry into the
174 pipeline. It begins testing all changes in parallel,
175 assuming that each change ahead in the pipeline will pass its
176 tests. If they all succeed, all the changes can be tested
177 and merged in parallel. If a change near the front of the
178 pipeline fails its tests, each change behind it ignores
179 whatever tests have been completed and are tested again
180 without the change in front. This way gate tests may run in
181 parallel but still be tested correctly, exactly as they will
182 appear in the repository when merged.
James E. Blair1761e862017-07-25 16:15:47 -0700183
James E. Blair9fd98ab2017-07-26 14:15:26 -0700184 For more detail on the theory and operation of Zuul's
185 dependent pipeline manager, see: :doc:`gating`.
James E. Blair1de8d402017-05-07 17:08:04 -0700186
James E. Blair9fd98ab2017-07-26 14:15:26 -0700187 .. zuul:attr:: allow-secrets
James E. Blairf17aa9c2017-07-05 13:21:23 -0700188
James E. Blair9fd98ab2017-07-26 14:15:26 -0700189 This is a boolean which can be used to prevent jobs which
190 require secrets from running in this pipeline. Some pipelines
191 run on proposed changes and therefore execute code which has not
192 yet been reviewed. In such a case, allowing a job to use a
193 secret could result in that secret being exposed. The default
194 is False, meaning that in order to run jobs with secrets, this
195 must be explicitly enabled on each Pipeline where that is safe.
James E. Blairf17aa9c2017-07-05 13:21:23 -0700196
James E. Blair9fd98ab2017-07-26 14:15:26 -0700197 For more information, see :ref:`secret`.
James E. Blair1de8d402017-05-07 17:08:04 -0700198
James E. Blair9fd98ab2017-07-26 14:15:26 -0700199 .. zuul:attr:: description
James E. Blair1de8d402017-05-07 17:08:04 -0700200
James E. Blair9fd98ab2017-07-26 14:15:26 -0700201 This field may be used to provide a textual description of the
202 pipeline. It may appear in the status page or in documentation.
James E. Blair1de8d402017-05-07 17:08:04 -0700203
James E. Blair9fd98ab2017-07-26 14:15:26 -0700204 .. zuul:attr:: success-message
James E. Blair1de8d402017-05-07 17:08:04 -0700205
James E. Blair9fd98ab2017-07-26 14:15:26 -0700206 The introductory text in reports when all the voting jobs are
207 successful. Defaults to "Build successful."
James E. Blair1de8d402017-05-07 17:08:04 -0700208
James E. Blair9fd98ab2017-07-26 14:15:26 -0700209 .. zuul:attr:: failure-message
James E. Blair1de8d402017-05-07 17:08:04 -0700210
James E. Blair9fd98ab2017-07-26 14:15:26 -0700211 The introductory text in reports when at least one voting job
212 fails. Defaults to "Build failed."
James E. Blair1de8d402017-05-07 17:08:04 -0700213
James E. Blair9fd98ab2017-07-26 14:15:26 -0700214 .. zuul:attr:: merge-failure-message
James E. Blair1de8d402017-05-07 17:08:04 -0700215
James E. Blair9fd98ab2017-07-26 14:15:26 -0700216 The introductory text in the message reported when a change
217 fails to merge with the current state of the repository.
218 Defaults to "Merge failed."
James E. Blair1de8d402017-05-07 17:08:04 -0700219
James E. Blair9fd98ab2017-07-26 14:15:26 -0700220 .. zuul:attr:: footer-message
James E. Blair1de8d402017-05-07 17:08:04 -0700221
James E. Blair9fd98ab2017-07-26 14:15:26 -0700222 Supplies additional information after test results. Useful for
223 adding information about the CI system such as debugging and
224 contact details.
James E. Blair1de8d402017-05-07 17:08:04 -0700225
James E. Blair9fd98ab2017-07-26 14:15:26 -0700226 .. zuul:attr:: trigger
James E. Blair1de8d402017-05-07 17:08:04 -0700227
James E. Blair9fd98ab2017-07-26 14:15:26 -0700228 At least one trigger source must be supplied for each pipeline.
229 Triggers are not exclusive -- matching events may be placed in
230 multiple pipelines, and they will behave independently in each
231 of the pipelines they match.
James E. Blair1de8d402017-05-07 17:08:04 -0700232
James E. Blair9fd98ab2017-07-26 14:15:26 -0700233 Triggers are loaded from their connection name. The driver type
234 of the connection will dictate which options are available. See
235 :ref:`drivers`.
James E. Blair1de8d402017-05-07 17:08:04 -0700236
James E. Blair9fd98ab2017-07-26 14:15:26 -0700237 .. zuul:attr:: require
James E. Blair1de8d402017-05-07 17:08:04 -0700238
James E. Blair9fd98ab2017-07-26 14:15:26 -0700239 If this section is present, it established pre-requisites for
240 any kind of item entering the Pipeline. Regardless of how the
241 item is to be enqueued (via any trigger or automatic dependency
242 resolution), the conditions specified here must be met or the
243 item will not be enqueued.
James E. Blair1de8d402017-05-07 17:08:04 -0700244
James E. Blair9fd98ab2017-07-26 14:15:26 -0700245 .. _pipeline-require-approval:
James E. Blair1de8d402017-05-07 17:08:04 -0700246
James E. Blair9fd98ab2017-07-26 14:15:26 -0700247 .. zuul:attr:: approval
James E. Blair1de8d402017-05-07 17:08:04 -0700248
James E. Blair9fd98ab2017-07-26 14:15:26 -0700249 This requires that a certain kind of approval be present for
250 the current patchset of the change (the approval could be
251 added by the event in question). It takes several
252 sub-parameters, all of which are optional and are combined
253 together so that there must be an approval matching all
254 specified requirements.
James E. Blair1de8d402017-05-07 17:08:04 -0700255
James E. Blair9fd98ab2017-07-26 14:15:26 -0700256 .. zuul:attr:: username
James E. Blair1de8d402017-05-07 17:08:04 -0700257
James E. Blair9fd98ab2017-07-26 14:15:26 -0700258 If present, an approval from this username is required. It is
259 treated as a regular expression.
James E. Blair1de8d402017-05-07 17:08:04 -0700260
James E. Blair9fd98ab2017-07-26 14:15:26 -0700261 .. zuul:attr:: email
James E. Blair1de8d402017-05-07 17:08:04 -0700262
James E. Blair9fd98ab2017-07-26 14:15:26 -0700263 If present, an approval with this email address is required. It
264 is treated as a regular expression.
James E. Blair1de8d402017-05-07 17:08:04 -0700265
James E. Blair9fd98ab2017-07-26 14:15:26 -0700266 .. zuul:attr:: email-filter (deprecated)
James E. Blair1de8d402017-05-07 17:08:04 -0700267
James E. Blair9fd98ab2017-07-26 14:15:26 -0700268 A deprecated alternate spelling of *email*. Only one of
269 *email* or *email_filter* should be used.
James E. Blair1de8d402017-05-07 17:08:04 -0700270
James E. Blair9fd98ab2017-07-26 14:15:26 -0700271 .. zuul:attr:: older-than
James E. Blaireff5a9d2017-06-20 00:00:37 -0700272
James E. Blair9fd98ab2017-07-26 14:15:26 -0700273 If present, the approval must be older than this amount
274 of time to match. Provide a time interval as a number
275 with a suffix of "w" (weeks), "d" (days), "h" (hours),
276 "m" (minutes), "s" (seconds). Example ``48h`` or ``2d``.
James E. Blair1de8d402017-05-07 17:08:04 -0700277
James E. Blair9fd98ab2017-07-26 14:15:26 -0700278 .. zuul:attr:: newer-than
James E. Blair1de8d402017-05-07 17:08:04 -0700279
James E. Blair9fd98ab2017-07-26 14:15:26 -0700280 If present, the approval must be newer than this amount
281 of time to match. Same format as "older-than".
James E. Blair1de8d402017-05-07 17:08:04 -0700282
James E. Blair9fd98ab2017-07-26 14:15:26 -0700283 Any other field is interpreted as a review category and
284 value pair. For example ``Verified: 1`` would require that
285 the approval be for a +1 vote in the "Verified" column. The
286 value may either be a single value or a list: ``Verified:
287 [1, 2]`` would match either a +1 or +2 vote.
James E. Blair1de8d402017-05-07 17:08:04 -0700288
James E. Blair9fd98ab2017-07-26 14:15:26 -0700289 .. zuul:attr:: open
James E. Blair1de8d402017-05-07 17:08:04 -0700290
James E. Blair9fd98ab2017-07-26 14:15:26 -0700291 A boolean value (``true`` or ``false``) that indicates whether
292 the change must be open or closed in order to be enqueued.
James E. Blair1de8d402017-05-07 17:08:04 -0700293
James E. Blair9fd98ab2017-07-26 14:15:26 -0700294 .. zuul:attr:: current-patchset
James E. Blaireff5a9d2017-06-20 00:00:37 -0700295
James E. Blair9fd98ab2017-07-26 14:15:26 -0700296 A boolean value (``true`` or ``false``) that indicates whether
297 the change must be the current patchset in order to be
298 enqueued.
James E. Blair1de8d402017-05-07 17:08:04 -0700299
James E. Blair9fd98ab2017-07-26 14:15:26 -0700300 .. zuul:attr:: status
James E. Blair1de8d402017-05-07 17:08:04 -0700301
James E. Blair9fd98ab2017-07-26 14:15:26 -0700302 A string value that corresponds with the status of the change
303 reported by the trigger.
James E. Blair1de8d402017-05-07 17:08:04 -0700304
James E. Blair9fd98ab2017-07-26 14:15:26 -0700305 .. zuul:attr:: reject
James E. Blair1de8d402017-05-07 17:08:04 -0700306
James E. Blair9fd98ab2017-07-26 14:15:26 -0700307 If this section is present, it establishes pre-requisites that
308 can block an item from being enqueued. It can be considered a
309 negative version of **require**.
James E. Blair1de8d402017-05-07 17:08:04 -0700310
James E. Blair9fd98ab2017-07-26 14:15:26 -0700311 .. zuul:attr:: approval
James E. Blair1de8d402017-05-07 17:08:04 -0700312
James E. Blair9fd98ab2017-07-26 14:15:26 -0700313 This takes a list of approvals. If an approval matches the
314 provided criteria the change can not be entered into the
315 pipeline. It follows the same syntax as the :ref:`"require
316 approval" pipeline above <pipeline-require-approval>`.
317
318 Example to reject a change with any negative vote::
319
320 reject:
321 approval:
322 - code-review: [-1, -2]
323
324 .. zuul:attr:: dequeue-on-new-patchset
325
326 Normally, if a new patchset is uploaded to a change that is in a
327 pipeline, the existing entry in the pipeline will be removed
328 (with jobs canceled and any dependent changes that can no longer
329 merge as well. To suppress this behavior (and allow jobs to
330 continue running), set this to ``false``. Default: ``true``.
331
332 .. zuul:attr:: ignore-dependencies
333
334 In any kind of pipeline (dependent or independent), Zuul will
335 attempt to enqueue all dependencies ahead of the current change
336 so that they are tested together (independent pipelines report
337 the results of each change regardless of the results of changes
338 ahead). To ignore dependencies completely in an independent
339 pipeline, set this to ``true``. This option is ignored by
340 dependent pipelines. The default is: ``false``.
341
342 .. zuul:attr:: precedence
343
344 Indicates how the build scheduler should prioritize jobs for
345 different pipelines. Each pipeline may have one precedence,
346 jobs for pipelines with a higher precedence will be run before
347 ones with lower. The value should be one of ``high``,
348 ``normal``, or ``low``. Default: ``normal``.
349
350 The following options configure *reporters*. Reporters are
351 complementary to triggers; where a trigger is an event on a
352 connection which causes Zuul to enqueue an item, a reporter is the
353 action performed on a connection when an item is dequeued after its
354 jobs complete. The actual syntax for a reporter is defined by the
355 driver which implements it. See :ref:`drivers` for more
356 information.
357
358 .. zuul:attr:: success
359
360 Describes where Zuul should report to if all the jobs complete
361 successfully. This section is optional; if it is omitted, Zuul
362 will run jobs and do nothing on success -- it will not report at
363 all. If the section is present, the listed reporters will be
364 asked to report on the jobs. The reporters are listed by their
365 connection name. The options available depend on the driver for
366 the supplied connection.
367
368 .. zuul:attr:: failure
369
370 These reporters describe what Zuul should do if at least one job
371 fails.
372
373 .. zuul:attr:: merge-failure
374
375 These reporters describe what Zuul should do if it is unable to
376 merge in the patchset. If no merge-failure reporters are listed
377 then the ``failure`` reporters will be used to notify of
378 unsuccessful merges.
379
380 .. zuul:attr:: start
381
382 These reporters describe what Zuul should do when a change is
383 added to the pipeline. This can be used, for example, to reset
384 a previously reported result.
385
386 .. zuul:attr:: disabled
387
388 These reporters describe what Zuul should do when a pipeline is
389 disabled. See ``disable-after-consecutive-failures``.
390
391 The following options can be used to alter Zuul's behavior to
392 mitigate situations in which jobs are failing frequently (perhaps
393 due to a problem with an external dependency, or unusually high
394 non-deterministic test failures).
395
396 .. zuul:attr:: disable-after-consecutive-failures
397
398 If set, a pipeline can enter a ''disabled'' state if too many
399 changes in a row fail. When this value is exceeded the pipeline
400 will stop reporting to any of the ``success``, ``failure`` or
401 ``merge-failure`` reporters and instead only report to the
402 ``disabled`` reporters. (No ``start`` reports are made when a
403 pipeline is disabled).
404
405 .. zuul:attr:: window
406
407 Dependent pipeline managers only. Zuul can rate limit dependent
408 pipelines in a manner similar to TCP flow control. Jobs are
409 only started for items in the queue if they are within the
410 actionable window for the pipeline. The initial length of this
411 window is configurable with this value. The value given should
412 be a positive integer value. A value of ``0`` disables rate
413 limiting on the DependentPipelineManager. Default: ``20``.
414
415 .. zuul:attr:: window-floor
416
417 Dependent pipeline managers only. This is the minimum value for
418 the window described above. Should be a positive non zero
419 integer value. Default: ``3``.
420
421 .. zuul:attr:: window-increase-type
422
423 Dependent pipeline managers only. This value describes how the
424 window should grow when changes are successfully merged by
425 zuul. A value of ``linear`` indicates that
426 ``window-increase-factor`` should be added to the previous
427 window value. A value of ``exponential`` indicates that
428 ``window-increase-factor`` should be multiplied against the
429 previous window value and the result will become the window
430 size. Default: ``linear``.
431
432 .. zuul:attr:: window-increase-factor
433
434 Dependent pipeline managers only. The value to be added or
435 multiplied against the previous window value to determine the
436 new window after successful change merges. Default: ``1``.
437
438 .. zuul:attr:: window-decrease-type
439
440 Dependent pipeline managers only. This value describes how the
441 window should shrink when changes are not able to be merged by
442 Zuul. A value of ``linear`` indicates that
443 ``window-decrease-factor`` should be subtracted from the
444 previous window value. A value of ``exponential`` indicates that
445 ``window-decrease-factor`` should be divided against the
446 previous window value and the result will become the window
447 size. Default: ``exponential``.
448
449 .. zuul:attr:: window-decrease-factor
450
451 Dependent pipline managers only. The value to be subtracted or
452 divided against the previous window value to determine the new
453 window after unsuccessful change merges. Default: ``2``.
James E. Blair1de8d402017-05-07 17:08:04 -0700454
455
456.. _job:
457
458Job
459~~~
460
461A job is a unit of work performed by Zuul on an item enqueued into a
462pipeline. Items may run any number of jobs (which may depend on each
463other). Each job is an invocation of an Ansible playbook with a
464specific inventory of hosts. The actual tasks that are run by the job
465appear in the playbook for that job while the attributes that appear in the
466Zuul configuration specify information about when, where, and how the
467job should be run.
468
469Jobs in Zuul support inheritance. Any job may specify a single parent
470job, and any attributes not set on the child job are collected from
471the parent job. In this way, a configuration structure may be built
472starting with very basic jobs which describe characteristics that all
473jobs on the system should have, progressing through stages of
474specialization before arriving at a particular job. A job may inherit
475from any other job in any project (however, if the other job is marked
476as `final`, some attributes may not be overidden).
477
478Jobs also support a concept called variance. The first time a job
479definition appears is called the reference definition of the job.
480Subsequent job definitions with the same name are called variants.
481These may have different selection criteria which indicate to Zuul
482that, for instance, the job should behave differently on a different
483git branch. Unlike inheritance, all job variants must be defined in
484the same project.
485
486When Zuul decides to run a job, it performs a process known as
487freezing the job. Because any number of job variants may be
488applicable, Zuul collects all of the matching variants and applies
489them in the order they appeared in the configuration. The resulting
490frozen job is built from attributes gathered from all of the
491matching variants. In this way, exactly what is run is dependent on
492the pipeline, project, branch, and content of the item.
493
494In addition to the job's main playbook, each job may specify one or
495more pre- and post-playbooks. These are run, in order, before and
496after (respectively) the main playbook. They may be used to set up
497and tear down resources needed by the main playbook. When combined
498with inheritance, they provide powerful tools for job construction. A
499job only has a single main playbook, and when inheriting from a
500parent, the child's main playbook overrides (or replaces) the
501parent's. However, the pre- and post-playbooks are appended and
502prepended in a nesting fashion. So if a parent job and child job both
503specified pre and post playbooks, the sequence of playbooks run would
504be:
505
506* parent pre-run playbook
507* child pre-run playbook
508* child playbook
509* child post-run playbook
510* parent post-run playbook
511
512Further inheritance would nest even deeper.
513
514Here is an example of two job definitions::
515
516 - job:
517 name: base
518 pre-run: copy-git-repos
519 post-run: copy-logs
520
521 - job:
522 name: run-tests
523 parent: base
524 nodes:
525 - name: test-node
James E. Blair9fd98ab2017-07-26 14:15:26 -0700526 image: fedora
James E. Blair1de8d402017-05-07 17:08:04 -0700527
528The following attributes are available on a job; all are optional
529unless otherwise specified:
530
531**name** (required)
532 The name of the job. By default, Zuul looks for a playbook with
533 this name to use as the main playbook for the job. This name is
534 also referenced later in a project pipeline configuration.
535
536**parent**
537 Specifies a job to inherit from. The parent job can be defined in
538 this or any other project. Any attributes not specified on a job
539 will be collected from its parent.
540
541**description**
542 A textual description of the job. Not currently used directly by
543 Zuul, but it is used by the zuul-sphinx extension to Sphinx to
544 auto-document Zuul jobs (in which case it is interpreted as
545 ReStructuredText.
546
547**success-message**
548 Normally when a job succeeds, the string "SUCCESS" is reported as
549 the result for the job. If set, this option may be used to supply a
550 different string. Default: "SUCCESS".
551
552**failure-message**
553 Normally when a job fails, the string "FAILURE" is reported as
554 the result for the job. If set, this option may be used to supply a
555 different string. Default: "FAILURE".
556
557**success-url**
James E. Blair88e79c02017-07-07 13:36:54 -0700558 When a job succeeds, this URL is reported along with the result. If
559 this value is not supplied, Zuul uses the content of the job
560 :ref:`return value <return_values>` **zuul.log_url**. This is
561 recommended as it allows the code which stores the URL to the job
562 artifacts to report exactly where they were stored. To override
563 this value, or if it is not set, supply an absolute URL in this
564 field. If a relative URL is supplied in this field, and
565 **zuul.log_url** is set, then the two will be combined to produce
566 the URL used for the report. This can be used to specify that
567 certain jobs should "deep link" into the stored job artifacts.
James E. Blair1de8d402017-05-07 17:08:04 -0700568 Default: none.
569
570**failure-url**
571 When a job fails, this URL is reported along with the result.
James E. Blair88e79c02017-07-07 13:36:54 -0700572 Otherwise behaves the same as **success-url**.
James E. Blair1de8d402017-05-07 17:08:04 -0700573
574**hold-following-changes**
575 In a dependent pipeline, this option may be used to indicate that no
576 jobs should start on any items which depend on the current item
577 until this job has completed successfully. This may be used to
578 conserve build resources, at the expense of inhibiting the
579 parallelization which speeds the processing of items in a dependent
580 pipeline. A boolean value, default: false.
581
582**voting**
583 Indicates whether the result of this job should be used in
584 determining the overall result of the item. A boolean value,
585 default: true.
586
587**semaphore**
588 The name of a :ref:`semaphore` which should be acquired and released
589 when the job begins and ends. If the semaphore is at maximum
590 capacity, then Zuul will wait until it can be acquired before
591 starting the job. Default: none.
592
593**tags**
594 Metadata about this job. Tags are units of information attached to
595 the job; they do not affect Zuul's behavior, but they can be used
596 within the job to characterize the job. For example, a job which
597 tests a certain subsystem could be tagged with the name of that
598 subsystem, and if the job's results are reported into a database,
599 then the results of all jobs affecting that subsystem could be
600 queried. This attribute is specified as a list of strings, and when
601 inheriting jobs or applying variants, tags accumulate in a set, so
602 the result is always a set of all the tags from all the jobs and
603 variants used in constructing the frozen job, with no duplication.
604 Default: none.
605
James E. Blaireff5a9d2017-06-20 00:00:37 -0700606**branches**
James E. Blair1de8d402017-05-07 17:08:04 -0700607 A regular expression (or list of regular expressions) which describe
608 on what branches a job should run (or in the case of variants: to
609 alter the behavior of a job for a certain branch).
610
611 If there is no job definition for a given job which matches the
612 branch of an item, then that job is not run for the item.
613 Otherwise, all of the job variants which match that branch (and any
614 other selection criteria) are used when freezing the job.
615
616 This example illustrates a job called *run-tests* which uses a
617 nodeset based on the current release of an operating system to
618 perform its tests, except when testing changes to the stable/2.0
619 branch, in which case it uses an older release::
620
621 - job:
622 name: run-tests
623 nodes: current-release
624
625 - job:
626 name: run-tests
627 branch: stable/2.0
628 nodes: old-release
629
630 In some cases, Zuul uses an implied value for the branch specifier
631 if none is supplied:
632
633 * For a job definition in a *config-project*, no implied branch
634 specifier is used. If no branch specifier appears, the job
635 applies to all branches.
636
637 * In the case of an *untrusted-project*, no implied branch specifier
638 is applied to the reference definition of a job. That is to say,
639 that if the first appearance of the job definition appears without
640 a branch specifier, then it will apply to all branches. Note that
641 when collecting its configuration, Zuul reads the `master` branch
642 of a given project first, then other branches in alphabetical
643 order.
644
645 * Any further job variants other than the reference definition in an
646 *untrusted-project* will, if they do not have a branch specifier,
647 will have an implied branch specifier for the current branch
648 applied.
649
650 This allows for the very simple and expected workflow where if a
651 project defines a job on the master branch with no branch specifier,
652 and then creates a new branch based on master, any changes to that
653 job definition within the new branch only affect that branch.
654
655**files**
656 This attribute indicates that the job should only run on changes
657 where the specified files are modified. This is a regular
658 expression or list of regular expressions. Default: none.
659
660**irrelevant-files**
661 This is a negative complement of `files`. It indicates that the job
662 should run unless *all* of the files changed match this list. In
663 other words, if the regular expression `docs/.*` is supplied, then
664 this job will not run if the only files changed are in the docs
665 directory. A regular expression or list of regular expressions.
666 Default: none.
667
668**auth**
669 Authentication information to be made available to the job. This is
670 a dictionary with two potential keys:
671
672 **inherit**
673 A boolean indicating that the authentication information referenced
674 by this job should be able to be inherited by child jobs. Normally
675 when a job inherits from another job, the auth section is not
676 included. This permits jobs to inherit the same basic structure and
677 playbook, but ensures that secret information is unable to be
678 exposed by a child job which may alter the job's behavior. If it is
679 safe for the contents of the authentication section to be used by
680 child jobs, set this to ``true``. Default: ``false``.
681
682 **secrets**
683 A list of secrets which may be used by the job. A :ref:`secret` is
684 a named collection of private information defined separately in the
685 configuration. The secrets that appear here must be defined in the
686 same project as this job definition.
687
688 In the future, other types of authentication information may be
689 added.
690
691**nodes**
692 A list of nodes which should be supplied to the job. This parameter
693 may be supplied either as a string, in which case it references a
694 :ref:`nodeset` definition which appears elsewhere in the
695 configuration, or a list, in which case it is interpreted in the
696 same way as a Nodeset definition (in essence, it is an anonymous
697 Node definition unique to this job). See the :ref:`nodeset`
698 reference for the syntax to use in that case.
699
700 If a job has an empty or no node definition, it will still run and
701 may be able to perform actions on the Zuul executor.
702
703**override-branch**
704 When Zuul runs jobs for a proposed change, it normally checks out
705 the branch associated with that change on every project present in
706 the job. If jobs are running on a ref (such as a branch tip or
707 tag), then that ref is normally checked out. This attribute is used
708 to override that behavior and indicate that this job should,
709 regardless of the branch for the queue item, use the indicated
710 branch instead. This can be used, for example, to run a previous
711 version of the software (from a stable maintenance branch) under
712 test even if the change being tested applies to a different branch
713 (this is only likely to be useful if there is some cross-branch
714 interaction with some component of the system being tested). See
715 also the project-specific **override-branch** attribute under
716 **required-projects** to apply this behavior to a subset of a job's
717 projects.
718
719**timeout**
720 The time in minutes that the job should be allowed to run before it
721 is automatically aborted and failure is reported. If no timeout is
722 supplied, the job may run indefinitely. Supplying a timeout is
723 highly recommended.
724
725**attempts**
726 When Zuul encounters an error running a job's pre-run playbook, Zuul
727 will stop and restart the job. Errors during the main or
728 post-run -playbook phase of a job are not affected by this parameter
729 (they are reported immediately). This parameter controls the number
730 of attempts to make before an error is reported. Default: 3.
731
732**pre-run**
Tobias Henkel2aade262017-07-12 16:09:06 +0200733 The name of a playbook or list of playbooks without file extension
734 to run before the main body of a job. The full path to the playbook
735 in the repo where the job is defined is expected.
James E. Blair1de8d402017-05-07 17:08:04 -0700736
737 When a job inherits from a parent, the child's pre-run playbooks are
738 run after the parent's. See :ref:`job` for more information.
739
740**post-run**
Tobias Henkel2aade262017-07-12 16:09:06 +0200741 The name of a playbook or list of playbooks without file extension
742 to run after the main body of a job. The full path to the playbook
743 in the repo where the job is defined is expected.
James E. Blair1de8d402017-05-07 17:08:04 -0700744
745 When a job inherits from a parent, the child's post-run playbooks
746 are run before the parent's. See :ref:`job` for more information.
747
748**run**
Tobias Henkel2aade262017-07-12 16:09:06 +0200749 The name of the main playbook for this job. This parameter is
750 not normally necessary, as it defaults to a playbook with the
751 same name as the job inside of the `playbooks/` directory (e.g.,
752 the `foo` job would default to `playbooks/foo`. However, if a
753 playbook with a different name is needed, it can be specified
754 here. The file extension is not required, but the full path
755 within the repo is. When a child inherits from a parent, a
756 playbook with the name of the child job is implicitly searched
757 first, before falling back on the playbook used by the parent
758 job (unless the child job specifies a ``run`` attribute, in which
759 case that value is used). Example::
760
761 run: playbooks/<name of the job>
James E. Blair1de8d402017-05-07 17:08:04 -0700762
763**roles**
764 A list of Ansible roles to prepare for the job. Because a job runs
765 an Ansible playbook, any roles which are used by the job must be
766 prepared and installed by Zuul before the job begins. This value is
767 a list of dictionaries, each of which indicates one of two types of
768 roles: a Galaxy role, which is simply a role that is installed from
769 Ansible Galaxy, or a Zuul role, which is a role provided by a
770 project managed by Zuul. Zuul roles are able to benefit from
James E. Blair74a82cf2017-07-12 17:23:08 -0700771 speculative merging and cross-project dependencies when used by
James E. Blair4eec8282017-07-12 17:33:26 -0700772 playbooks in untrusted projects. Roles are added to the Ansible
773 role path in the order they appear on the job -- roles earlier in
774 the list will take precedence over those which follow.
James E. Blair74a82cf2017-07-12 17:23:08 -0700775
776 In the case of job inheritance or variance, the roles used for each
777 of the playbooks run by the job will be only those which were
778 defined along with that playbook. If a child job inherits from a
779 parent which defines a pre and post playbook, then the pre and post
780 playbooks it inherits from the parent job will run only with the
781 roles that were defined on the parent. If the child adds its own
782 pre and post playbooks, then any roles added by the child will be
783 available to the child's playbooks. This is so that a job which
784 inherits from a parent does not inadvertantly alter the behavior of
James E. Blair4eec8282017-07-12 17:33:26 -0700785 the parent's playbooks by the addition of conflicting roles. Roles
786 added by a child will appear before those it inherits from its
787 parent.
James E. Blair1de8d402017-05-07 17:08:04 -0700788
789 A project which supplies a role may be structured in one of two
790 configurations: a bare role (in which the role exists at the root of
791 the project), or a contained role (in which the role exists within
792 the `roles/` directory of the project, perhaps along with other
793 roles). In the case of a contained role, the `roles/` directory of
794 the project is added to the role search path. In the case of a bare
795 role, the project itself is added to the role search path. In case
796 the name of the project is not the name under which the role should
797 be installed (and therefore referenced from Ansible), the `name`
798 attribute may be used to specify an alternate.
799
James E. Blairbb94dfa2017-07-11 07:45:19 -0700800 A job automatically has the project in which it is defined added to
801 the roles path if that project appears to contain a role or `roles/`
802 directory. By default, the project is added to the path under its
803 own name, however, that may be changed by explicitly listing the
804 project in the roles list in the usual way.
805
James E. Blaireff5a9d2017-06-20 00:00:37 -0700806 .. note:: galaxy roles are not yet implemented
807
James E. Blair1de8d402017-05-07 17:08:04 -0700808 **galaxy**
809 The name of the role in Ansible Galaxy. If this attribute is
810 supplied, Zuul will search Ansible Galaxy for a role by this name
811 and install it. Mutually exclusive with ``zuul``; either
812 ``galaxy`` or ``zuul`` must be supplied.
813
814 **zuul**
815 The name of a Zuul project which supplies the role. Mutually
816 exclusive with ``galaxy``; either ``galaxy`` or ``zuul`` must be
817 supplied.
818
819 **name**
820 The installation name of the role. In the case of a bare role,
821 the role will be made available under this name. Ignored in the
822 case of a contained role.
823
824**required-projects**
825 A list of other projects which are used by this job. Any Zuul
826 projects specified here will also be checked out by Zuul into the
827 working directory for the job. Speculative merging and cross-repo
828 dependencies will be honored.
829
830 The format for this attribute is either a list of strings or
831 dictionaries. Strings are interpreted as project names,
832 dictionaries may have the following attributes:
833
834 **name**
835 The name of the required project.
836
837 **override-branch**
838 When Zuul runs jobs for a proposed change, it normally checks out
839 the branch associated with that change on every project present in
840 the job. If jobs are running on a ref (such as a branch tip or
841 tag), then that ref is normally checked out. This attribute is
842 used to override that behavior and indicate that this job should,
843 regardless of the branch for the queue item, use the indicated
844 branch instead, for only this project. See also the
845 **override-branch** attribute of jobs to apply the same behavior
846 to all projects in a job.
847
848**vars**
849
850A dictionary of variables to supply to Ansible. When inheriting from
851a job (or creating a variant of a job) vars are merged with previous
852definitions. This means a variable definition with the same name will
853override a previously defined variable, but new variable names will be
854added to the set of defined variables.
855
856**dependencies**
857 A list of other jobs upon which this job depends. Zuul will not
858 start executing this job until all of its dependencies have
859 completed successfully, and if one or more of them fail, this job
860 will not be run.
861
862**allowed-projects**
863 A list of Zuul projects which may use this job. By default, a job
864 may be used by any other project known to Zuul, however, some jobs
865 use resources or perform actions which are not appropriate for other
866 projects. In these cases, a list of projects which are allowed to
867 use this job may be supplied. If this list is not empty, then it
868 must be an exhaustive list of all projects permitted to use the job.
869 The current project (where the job is defined) is not automatically
870 included, so if it should be able to run this job, then it must be
871 explicitly listed. Default: the empty list (all projects may use
872 the job).
873
874
875.. _project:
876
877Project
878~~~~~~~
879
880A project corresponds to a source code repository with which Zuul is
881configured to interact. The main responsibility of the `Project`
882configuration item is to specify which jobs should run in which
883pipelines for a given project. Within each `Project` definition, a
884section for each `Pipeline` may appear. This project-pipeline
885definition is what determines how a project participates in a
886pipeline.
887
888Consider the following `Project` definition::
889
890 - project:
891 name: yoyodyne
892 check:
893 jobs:
894 - check-syntax
895 - unit-tests
896 gate:
897 queue: integrated
898 jobs:
899 - unit-tests
900 - integration-tests
901
902The project has two project-pipeline stanzas, one for the `check`
903pipeline, and one for `gate`. Each specifies which jobs shuld run
904when a change for that project enteres the respective pipeline -- when
905a change enters `check`, the `check-syntax` and `unit-test` jobs are
906run.
907
908Pipelines which use the dependent pipeline manager (e.g., the `gate`
909example shown earlier) maintain separate queues for groups of
910projects. When Zuul serializes a set of changes which represent
911future potential project states, it must know about all of the
912projects within Zuul which may have an effect on the outcome of the
913jobs it runs. If project *A* uses project *B* as a library, then Zuul
914must be told about that relationship so that it knows to serialize
915changes to A and B together, so that it does not merge a change to B
916while it is testing a change to A.
917
918Zuul could simply assume that all projects are related, or even infer
919relationships by which projects a job indicates it uses, however, in a
920large system that would become unwieldy very quickly, and
921unnecessarily delay changes to unrelated projects. To allow for
922flexibility in the construction of groups of related projects, the
923change queues used by dependent pipeline managers are specified
924manually. To group two or more related projects into a shared queue
925for a dependent pipeline, set the ``queue`` parameter to the same
926value for those projects.
927
928The `gate` project-pipeline definition above specifies that this
929project participates in the `integrated` shared queue for that
930pipeline.
931
932In addition to a project-pipeline definition for one or more
933`Pipelines`, the following attributes may appear in a Project:
934
935**name** (required)
936 The name of the project. If Zuul is configured with two or more
937 unique projects with the same name, the canonical hostname for the
938 project should be included (e.g., `git.example.com/foo`).
939
940**templates**
941 A list of :ref:`project-template` references; the project-pipeline
942 definitions of each Project Template will be applied to this
943 project. If more than one template includes jobs for a given
944 pipeline, they will be combined, as will any jobs specified in
945 project-pipeline definitions on the project itself.
946
947.. _project-template:
948
949Project Template
950~~~~~~~~~~~~~~~~
951
952A Project Template defines one or more project-pipeline definitions
953which can be re-used by multiple projects.
954
955A Project Template uses the same syntax as a :ref:`project`
956definition, however, in the case of a template, the ``name`` attribute
957does not refer to the name of a project, but rather names the template
958so that it can be referenced in a `Project` definition.
959
960.. _secret:
961
962Secret
963~~~~~~
964
965A Secret is a collection of private data for use by one or more jobs.
966In order to maintain the security of the data, the values are usually
967encrypted, however, data which are not sensitive may be provided
968unencrypted as well for convenience.
969
970A Secret may only be used by jobs defined within the same project. To
971use a secret, a :ref:`job` must specify the secret within its `auth`
972section. To protect against jobs in other repositories declaring a
973job with a secret as a parent and then exposing that secret, jobs
974which inherit from a job with secrets will not inherit the secrets
975themselves. To alter that behavior, see the `inherit` job attribute.
976Further, jobs which do not permit children to inherit secrets (the
977default) are also automatically marked `final`, meaning that their
978execution related attributes may not be changed in a project-pipeline
979stanza. This is to protect against a job with secrets defined in one
980project being used by another project in a way which might expose the
981secrets. If a job with secrets is unsafe to be used by other
982projects, the `allowed-projects` job attribute can be used to restrict
983the projects which can invoke that job. Finally, pipelines which are
984used to execute proposed but unreviewed changes can set the
985`allow-secrets` attribute to indicate that they should not supply
986secrets at all in order to protect against someone proposing a change
987which exposes a secret.
988
989The following attributes are required:
990
991**name** (required)
992 The name of the secret, used in a :ref:`Job` definition to request
993 the secret.
994
995**data** (required)
996 A dictionary which will be added to the Ansible variables available
997 to the job. The values can either be plain text strings, or
998 encrypted values. See :ref:`encryption` for more information.
999
1000.. _nodeset:
1001
1002Nodeset
1003~~~~~~~
1004
1005A Nodeset is a named collection of nodes for use by a job. Jobs may
1006specify what nodes they require individually, however, by defining
1007groups of node types once and referring to them by name, job
1008configuration may be simplified.
1009
1010A Nodeset requires two attributes:
1011
1012**name** (required)
1013 The name of the Nodeset, to be referenced by a :ref:`job`.
1014
1015**nodes** (required)
1016 A list of node definitions, each of which has the following format:
1017
1018 **name** (required)
1019 The name of the node. This will appear in the Ansible inventory
1020 for the job.
1021
1022 **label** (required)
1023 The Nodepool label for the node. Zuul will request a node with
1024 this label.
1025
1026.. _semaphore:
1027
1028Semaphore
1029~~~~~~~~~
1030
1031Semaphores can be used to restrict the number of certain jobs which
1032are running at the same time. This may be useful for jobs which
1033access shared or limited resources. A semaphore has a value which
1034represents the maximum number of jobs which use that semaphore at the
1035same time.
1036
1037Semaphores are never subject to dynamic reconfiguration. If the value
1038of a semaphore is changed, it will take effect only when the change
1039where it is updated is merged. An example follows::
1040
1041 - semaphore:
1042 name: semaphore-foo
1043 max: 5
1044 - semaphore:
1045 name: semaphore-bar
1046 max: 3
1047
1048The following attributes are available:
1049
1050**name** (required)
1051 The name of the semaphore, referenced by jobs.
1052
1053**max**
1054 The maximum number of running jobs which can use this semaphore.
1055 Defaults to 1.