blob: a367aa0fe80da998cdda62aad17069268d228e49 [file] [log] [blame]
James E. Blaireff5a9d2017-06-20 00:00:37 -07001:title: Job Content
2
3Job Content
4===========
5
6Zuul jobs are implemneted as Ansible playbooks. Zuul prepares the
7repositories used for a job, installs any required Ansible roles, and
8then executes the job's playbooks. Any setup or artifact collection
9required is the responsibility of the job itself. While this flexible
10arrangement allows for almost any kind of job to be run by Zuul,
11batteries are included. Zuul has a standard library of jobs upon
12which to build.
13
14Working Directory
15-----------------
16
17Before starting each job, the Zuul executor creates a directory to
18hold all of the content related to the job. This includes some
19directories which are used by Zuul to configure and run Ansible and
20may not be accessible, as well as a directory tree, under ``work/``,
21that is readable and writable by the job. The hierarchy is:
22
23**work/**
24 The working directory of the job.
25
26**work/src/**
27 Contains the prepared git repositories for the job.
28
29**work/logs/**
30 Where the Ansible log for the job is written; your job
31 may place other logs here as well.
32
33Git Repositories
34----------------
35
36The git repositories in ``work/src`` contain the repositories for all
37of the projects specified in the ``required-projects`` section of the
38job, plus the project associated with the queue item if it isn't
39already in that list. In the case of a proposed change, that change
40and all of the changes ahead of it in the pipeline queue will already
41be merged into their respective repositories and target branches. The
42change's project will have the change's branch checked out, as will
43all of the other projects, if that branch exists (otherwise, a
44fallback or default branch will be used). If your job needs to
45operate on multiple branches, simply checkout the appropriate branches
46of these git repos to ensure that the job results reflect the proposed
47future state that Zuul is testing, and all dependencies are present.
48Do not use any git remotes; the local repositories are guaranteed to
49be up to date.
50
James E. Blair4d5dd252017-06-23 21:40:56 +010051The repositories will be placed on the filesystem in directories
52corresponding with the canonical hostname of their source connection.
53For example::
54
55 work/src/git.example.com/project1
56 work/src/github.com/project2
57
58Is the layout that would be present for a job which included project1
59from the connection associated to git.example.com and project2 from
60GitHub. This helps avoid collisions between projects with the same
61name, and some language environments, such as Go, expect repositories
62in this format.
63
James E. Blaireff5a9d2017-06-20 00:00:37 -070064Note that these git repositories are located on the executor; in order
65to be useful to most kinds of jobs, they will need to be present on
66the test nodes. The ``base`` job in the standard library contains a
67pre-playbook which copies the repositories to all of the job's nodes.
68It is recommended to always inherit from this base job to ensure that
69behavior.
70
71.. TODO: link to base job documentation and/or document src (and logs?) directory
72
James E. Blair28c8e3b2017-07-17 16:27:50 -070073Variables
74---------
75
76Any variables specified in the job definition are available as Ansible
77host variables. They are added to the `vars` section of the inventory
78file under the `all` hosts group, so they are available to all hosts.
79Simply refer to them by the name specified in the job's `vars`
80section.
81
82Secrets
83~~~~~~~
84
85Secrets also appear as variables available to Ansible. Unlike job
86variables, these are not added to the inventory file (so that the
87inventory file may be kept for debugging purposes without revealing
88secrets). But they are still available to Ansible as normal
89variables. Because secrets are groups of variables, they will appear
90as a dictionary structure in templates, with the dictionary itself
91being the name of the secret, and its members the individual items in
92the secret. For example, a secret defined as::
93
94 - secret:
95 name: credentials
96 data:
97 username: foo
98 password: bar
99
100Might be used in a template as::
101
102 {{ credentials.username }} {{ credentials.password }}
103
104.. TODO: xref job vars
105
James E. Blaireff5a9d2017-06-20 00:00:37 -0700106Zuul Variables
James E. Blair28c8e3b2017-07-17 16:27:50 -0700107~~~~~~~~~~~~~~
James E. Blaireff5a9d2017-06-20 00:00:37 -0700108
109Zuul supplies not only the variables specified by the job definition
James E. Blair21037782017-07-19 11:56:55 -0700110to Ansible, but also some variables from the Zuul itself.
111
James E. Blairbabefce2017-07-20 17:14:54 -0700112When a pipeline is triggered by an action, it enqueues items which may
James E. Blair21037782017-07-19 11:56:55 -0700113vary based on the pipeline's configuration. For example, when a new
114change is created, that change may be enqueued into the pipeline,
115while a tag may be enqueued into the pipeline when it is pushed.
116
117Information about these items is available to jobs. All of the items
118enqueued in a pipeline are git references, and therefore share some
119attributes in common. But other attributes may vary based on the type
120of item.
121
122All items provide the following information as Ansible variables:
123
James E. Blaira9fbb6c2017-07-20 16:07:30 -0700124**zuul.build**
James E. Blair21037782017-07-19 11:56:55 -0700125 The UUID of the build. A build is a single execution of a job.
126 When an item is enqueued into a pipeline, this usually results in
127 one build of each job configured for that item's project. However,
128 items may be re-enqueued in which case another build may run. In
129 dependent pipelines, the same job may run multiple times for the
130 same item as circumstances change ahead in the queue. Each time a
131 job is run, for whatever reason, it is acompanied with a new
132 unique id.
133
James E. Blair21037782017-07-19 11:56:55 -0700134**zuul.buildset**
135 The build set UUID. When Zuul runs jobs for an item, the collection
136 of those jobs is known as a buildset. If the configuration of items
137 ahead in a dependent pipeline changes, Zuul creates a new buildset
138 and restarts all of the jobs.
139
140**zuul.ref**
141 The git ref of the item. This will be the full path (e.g.,
142 'refs/heads/master' or 'refs/changes/...').
143
144**zuul.pipeline**
145 The name of the pipeline in which the job is being run.
146
147**zuul.job**
148 The name of the job being run.
149
150**zuul.project**
151 The item's project. This is a data structure with the following
152 fields:
153
154**zuul.project.name**
155 The name of the project, excluding hostname. E.g., `org/project`.
156
157**zuul.project.canonical_hostname**
158 The canonical hostname where the project lives. E.g.,
159 `git.example.com`.
160
161**zuul.project.canonical_name**
162 The full canonical name of the project including hostname. E.g.,
163 `git.example.com/org/project`.
164
165**zuul.tenant**
166 The name of the current Zuul tenant.
167
James E. Blair9d46f092017-07-20 16:06:20 -0700168**zuul.jobtags**
James E. Blair21037782017-07-19 11:56:55 -0700169 A list of tags associated with the job. Not to be confused with git
170 tags, these are simply free-form text fields that can be used by the
171 job for reporting or classification purposes.
172
James E. Blair21037782017-07-19 11:56:55 -0700173**zuul.items**
James E. Blair21037782017-07-19 11:56:55 -0700174
James E. Blaira08f4592017-07-20 16:35:55 -0700175 A list of dictionaries, each representing an item being tested with
176 this change with the format:
James E. Blair21037782017-07-19 11:56:55 -0700177
James E. Blaira08f4592017-07-20 16:35:55 -0700178 **project.name**
179 The name of the project, excluding hostname. E.g., `org/project`.
180
181 **project.canonical_hostname**
182 The canonical hostname where the project lives. E.g.,
183 `git.example.com`.
184
185 **project.canonical_name**
186 The full canonical name of the project including hostname. E.g.,
187 `git.example.com/org/project`.
188
189 **branch**
190 The target branch of the change (without the `refs/heads/` prefix).
191
192 **change**
193 The identifier for the change.
194
195 **patchset**
196 The patchset identifier for the change. If a change is revised,
197 this will have a different value.
James E. Blair21037782017-07-19 11:56:55 -0700198
199Change Items
200++++++++++++
201
202A change to the repository. Most often, this will be a git reference
203which has not yet been merged into the repository (e.g., a gerrit
204change or a GitHub pull request). The following additional variables
205are available:
206
207**zuul.branch**
208 The target branch of the change (without the `refs/heads/` prefix).
209
210**zuul.change**
211 The identifier for the change.
212
213**zuul.patchset**
214 The patchset identifier for the change. If a change is revised,
215 this will have a different value.
216
217Branch Items
218++++++++++++
219
220This represents a branch tip. This item may have been enqueued
221because the branch was updated (via a change having merged, or a
222direct push). Or it may have been enqueued by a timer for the purpose
223of verifying the current condition of the branch. The following
224additional variables are available:
225
226**zuul.branch**
227 The name of the item's branch (without the `refs/heads/` prefix).
228
229**zuul.oldrev**
230 If the item was enqueued as the result of a change merging or being
231 pushed to the branch, the git sha of the old revision will be
James E. Blair673dbd12017-07-21 10:02:49 -0700232 included here. Otherwise, this variable will be undefined.
James E. Blair21037782017-07-19 11:56:55 -0700233
234**zuul.newrev**
235 If the item was enqueued as the result of a change merging or being
236 pushed to the branch, the git sha of the new revision will be
James E. Blair673dbd12017-07-21 10:02:49 -0700237 included here. Otherwise, this variable will be undefined.
James E. Blair21037782017-07-19 11:56:55 -0700238
239Tag Items
240+++++++++
241
242This represents a git tag. The item may have been enqueued because a
243tag was created or deleted. The following additional variables are
244available:
245
246**zuul.tag**
247 The name of the item's tag (without the `refs/tags/` prefix).
248
249**zuul.oldrev**
James E. Blair673dbd12017-07-21 10:02:49 -0700250 If the item was enqueued as the result of a tag being deleted, the
251 previous git sha of the tag will be included here. If the tag was
252 created, this will be set to the value
253 0000000000000000000000000000000000000000.
James E. Blair21037782017-07-19 11:56:55 -0700254
255**zuul.newrev**
James E. Blair673dbd12017-07-21 10:02:49 -0700256 If the item was enqueued as the result of a tag being created, the
257 new git sha of the tag will be included here. If the tag was
258 deleted, this will be set to the value
259 0000000000000000000000000000000000000000.
James E. Blair21037782017-07-19 11:56:55 -0700260
261Ref Items
262+++++++++
263
264This represents a git reference that is neither a change, branch, or
265tag. Note that all items include a `ref` attribute which may be used
266to identify the ref. The following additional variables are
267available:
268
269**zuul.oldrev**
James E. Blair673dbd12017-07-21 10:02:49 -0700270 If the item was enqueued as the result of a ref being deleted, the
271 previous git sha of the ref will be included here. If the ref was
272 created, this will be set to the value
273 0000000000000000000000000000000000000000.
James E. Blair21037782017-07-19 11:56:55 -0700274
275**zuul.newrev**
James E. Blair673dbd12017-07-21 10:02:49 -0700276 If the item was enqueued as the result of a ref being created, the
277 new git sha of the ref will be included here. If the ref was
278 deleted, this will be set to the value
279 0000000000000000000000000000000000000000.
James E. Blair21037782017-07-19 11:56:55 -0700280
281Working Directory
282+++++++++++++++++
283
284Additionally, some information about the working directory and the
285executor running the job is available:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700286
287**zuul.executor.hostname**
288 The hostname of the executor.
289
290**zuul.executor.src_root**
291 The path to the source directory.
292
293**zuul.executor.log_root**
294 The path to the logs directory.
295
296SSH Keys
297--------
298
299Zuul starts each job with an SSH agent running and the key used to
300access the job's nodes added to that agent. Generally you won't need
301to be aware of this since Ansible will use this when performing any
302tasks on remote nodes. However, under some circumstances you may want
303to interact with the agent. For example, you may wish to add a key
304provided as a secret to the job in order to access a specific host, or
305you may want to, in a pre-playbook, replace the key used to log into
306the assigned nodes in order to further protect it from being abused by
307untrusted job content.
308
309.. TODO: describe standard lib and link to published docs for it.
310
James E. Blair88e79c02017-07-07 13:36:54 -0700311.. _return_values:
312
James E. Blair196f61a2017-06-30 15:42:29 -0700313Return Values
314-------------
315
316The job may return some values to Zuul to affect its behavior. To
317return a value, use the *zuul_return* Ansible module in a job
318playbook. For example::
319
320 tasks:
321 - zuul_return:
322 data:
323 foo: bar
324
325Will return the dictionary "{'foo': 'bar'}" to Zuul.
326
327.. TODO: xref to section describing formatting
328
329Several uses of these values are planned, but the only currently
330implemented use is to set the log URL for a build. To do so, set the
331**zuul.log_url** value. For example::
332
333 tasks:
334 - zuul_return:
335 data:
336 zuul:
337 log_url: http://logs.example.com/path/to/build/logs