James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 1 | :title: Job Content |
| 2 | |
| 3 | Job Content |
| 4 | =========== |
| 5 | |
David Shrewsbury | c50cb57 | 2017-08-04 11:55:01 -0400 | [diff] [blame] | 6 | Zuul jobs are implemented as Ansible playbooks. Zuul prepares the |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 7 | repositories used for a job, installs any required Ansible roles, and |
| 8 | then executes the job's playbooks. Any setup or artifact collection |
| 9 | required is the responsibility of the job itself. While this flexible |
| 10 | arrangement allows for almost any kind of job to be run by Zuul, |
| 11 | batteries are included. Zuul has a standard library of jobs upon |
| 12 | which to build. |
| 13 | |
| 14 | Working Directory |
| 15 | ----------------- |
| 16 | |
| 17 | Before starting each job, the Zuul executor creates a directory to |
| 18 | hold all of the content related to the job. This includes some |
| 19 | directories which are used by Zuul to configure and run Ansible and |
| 20 | may not be accessible, as well as a directory tree, under ``work/``, |
| 21 | that 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 | |
| 33 | Git Repositories |
| 34 | ---------------- |
| 35 | |
| 36 | The git repositories in ``work/src`` contain the repositories for all |
| 37 | of the projects specified in the ``required-projects`` section of the |
| 38 | job, plus the project associated with the queue item if it isn't |
| 39 | already in that list. In the case of a proposed change, that change |
| 40 | and all of the changes ahead of it in the pipeline queue will already |
| 41 | be merged into their respective repositories and target branches. The |
| 42 | change's project will have the change's branch checked out, as will |
| 43 | all of the other projects, if that branch exists (otherwise, a |
| 44 | fallback or default branch will be used). If your job needs to |
| 45 | operate on multiple branches, simply checkout the appropriate branches |
| 46 | of these git repos to ensure that the job results reflect the proposed |
| 47 | future state that Zuul is testing, and all dependencies are present. |
| 48 | Do not use any git remotes; the local repositories are guaranteed to |
| 49 | be up to date. |
| 50 | |
James E. Blair | 4d5dd25 | 2017-06-23 21:40:56 +0100 | [diff] [blame] | 51 | The repositories will be placed on the filesystem in directories |
| 52 | corresponding with the canonical hostname of their source connection. |
| 53 | For example:: |
| 54 | |
| 55 | work/src/git.example.com/project1 |
| 56 | work/src/github.com/project2 |
| 57 | |
| 58 | Is the layout that would be present for a job which included project1 |
| 59 | from the connection associated to git.example.com and project2 from |
| 60 | GitHub. This helps avoid collisions between projects with the same |
| 61 | name, and some language environments, such as Go, expect repositories |
| 62 | in this format. |
| 63 | |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 64 | Note that these git repositories are located on the executor; in order |
| 65 | to be useful to most kinds of jobs, they will need to be present on |
| 66 | the test nodes. The ``base`` job in the standard library contains a |
| 67 | pre-playbook which copies the repositories to all of the job's nodes. |
| 68 | It is recommended to always inherit from this base job to ensure that |
| 69 | behavior. |
| 70 | |
| 71 | .. TODO: link to base job documentation and/or document src (and logs?) directory |
| 72 | |
James E. Blair | 28c8e3b | 2017-07-17 16:27:50 -0700 | [diff] [blame] | 73 | Variables |
| 74 | --------- |
| 75 | |
Jamie Lennox | 7655b55 | 2017-03-17 12:33:38 +1100 | [diff] [blame] | 76 | There are several sources of variables which are available to Ansible: |
| 77 | variables defined in jobs, secrets, and site-wide variables. The |
| 78 | order of precedence is: |
| 79 | |
| 80 | * Site-wide variables |
| 81 | |
| 82 | * Secrets |
| 83 | |
| 84 | * Job variables |
| 85 | |
James E. Blair | 698703c | 2017-09-15 20:58:30 -0600 | [diff] [blame] | 86 | * Parent job results |
| 87 | |
Jamie Lennox | 7655b55 | 2017-03-17 12:33:38 +1100 | [diff] [blame] | 88 | Meaning that a site-wide variable with the same name as any other will |
| 89 | override its value, and similarly, secrets override job variables of |
James E. Blair | 698703c | 2017-09-15 20:58:30 -0600 | [diff] [blame] | 90 | the same name which override data returned from parent jobs. Each of |
| 91 | the sources is described below. |
Jamie Lennox | 7655b55 | 2017-03-17 12:33:38 +1100 | [diff] [blame] | 92 | |
| 93 | |
| 94 | Job Variables |
| 95 | ~~~~~~~~~~~~~ |
| 96 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 97 | Any variables specified in the job definition (using the |
| 98 | :attr:`job.vars` attribute) are available as Ansible host variables. |
| 99 | They are added to the ``vars`` section of the inventory file under the |
| 100 | ``all`` hosts group, so they are available to all hosts. Simply refer |
| 101 | to them by the name specified in the job's ``vars`` section. |
James E. Blair | 28c8e3b | 2017-07-17 16:27:50 -0700 | [diff] [blame] | 102 | |
| 103 | Secrets |
| 104 | ~~~~~~~ |
| 105 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 106 | :ref:`Secrets <secret>` also appear as variables available to Ansible. |
| 107 | Unlike job variables, these are not added to the inventory file (so |
| 108 | that the inventory file may be kept for debugging purposes without |
| 109 | revealing secrets). But they are still available to Ansible as normal |
James E. Blair | 28c8e3b | 2017-07-17 16:27:50 -0700 | [diff] [blame] | 110 | variables. Because secrets are groups of variables, they will appear |
| 111 | as a dictionary structure in templates, with the dictionary itself |
| 112 | being the name of the secret, and its members the individual items in |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 113 | the secret. For example, a secret defined as: |
| 114 | |
| 115 | .. code-block:: yaml |
James E. Blair | 28c8e3b | 2017-07-17 16:27:50 -0700 | [diff] [blame] | 116 | |
| 117 | - secret: |
| 118 | name: credentials |
| 119 | data: |
| 120 | username: foo |
| 121 | password: bar |
| 122 | |
| 123 | Might be used in a template as:: |
| 124 | |
| 125 | {{ credentials.username }} {{ credentials.password }} |
| 126 | |
James E. Blair | 892cca6 | 2017-08-09 11:36:58 -0700 | [diff] [blame] | 127 | Secrets are only available to playbooks associated with the job |
| 128 | definition which uses the secret; they are not available to playbooks |
| 129 | associated with child jobs or job variants. |
James E. Blair | 28c8e3b | 2017-07-17 16:27:50 -0700 | [diff] [blame] | 130 | |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 131 | Zuul Variables |
James E. Blair | 28c8e3b | 2017-07-17 16:27:50 -0700 | [diff] [blame] | 132 | ~~~~~~~~~~~~~~ |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 133 | |
| 134 | Zuul supplies not only the variables specified by the job definition |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 135 | to Ansible, but also some variables from Zuul itself. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 136 | |
James E. Blair | babefce | 2017-07-20 17:14:54 -0700 | [diff] [blame] | 137 | When a pipeline is triggered by an action, it enqueues items which may |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 138 | vary based on the pipeline's configuration. For example, when a new |
| 139 | change is created, that change may be enqueued into the pipeline, |
| 140 | while a tag may be enqueued into the pipeline when it is pushed. |
| 141 | |
| 142 | Information about these items is available to jobs. All of the items |
| 143 | enqueued in a pipeline are git references, and therefore share some |
| 144 | attributes in common. But other attributes may vary based on the type |
| 145 | of item. |
| 146 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 147 | .. var:: zuul |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 148 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 149 | All items provide the following information as Ansible variables |
| 150 | under the ``zuul`` key: |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 151 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 152 | .. var:: build |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 153 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 154 | The UUID of the build. A build is a single execution of a job. |
| 155 | When an item is enqueued into a pipeline, this usually results |
| 156 | in one build of each job configured for that item's project. |
| 157 | However, items may be re-enqueued in which case another build |
| 158 | may run. In dependent pipelines, the same job may run multiple |
| 159 | times for the same item as circumstances change ahead in the |
| 160 | queue. Each time a job is run, for whatever reason, it is |
| 161 | acompanied with a new unique id. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 162 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 163 | .. var:: buildset |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 164 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 165 | The build set UUID. When Zuul runs jobs for an item, the |
| 166 | collection of those jobs is known as a buildset. If the |
| 167 | configuration of items ahead in a dependent pipeline changes, |
| 168 | Zuul creates a new buildset and restarts all of the jobs. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 169 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 170 | .. var:: ref |
James E. Blair | 2ef29e9 | 2017-07-21 15:25:05 -0700 | [diff] [blame] | 171 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 172 | The git ref of the item. This will be the full path (e.g., |
| 173 | `refs/heads/master` or `refs/changes/...`). |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 174 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 175 | .. var:: pipeline |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 176 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 177 | The name of the pipeline in which the job is being run. |
Monty Taylor | 299f94b | 2017-07-28 17:16:36 -0500 | [diff] [blame] | 178 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 179 | .. var:: job |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 180 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 181 | The name of the job being run. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 182 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 183 | .. var:: voting |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 184 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 185 | A boolean indicating whether the job is voting. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 186 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 187 | .. var:: project |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 188 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 189 | The item's project. This is a data structure with the following |
| 190 | fields: |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 191 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 192 | .. var:: name |
Monty Taylor | 299f94b | 2017-07-28 17:16:36 -0500 | [diff] [blame] | 193 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 194 | The name of the project, excluding hostname. E.g., `org/project`. |
Monty Taylor | 299f94b | 2017-07-28 17:16:36 -0500 | [diff] [blame] | 195 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 196 | .. var:: short_name |
Monty Taylor | 299f94b | 2017-07-28 17:16:36 -0500 | [diff] [blame] | 197 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 198 | The name of the project, excluding directories or |
| 199 | organizations. E.g., `project`. |
Monty Taylor | 299f94b | 2017-07-28 17:16:36 -0500 | [diff] [blame] | 200 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 201 | .. var:: canonical_hostname |
Monty Taylor | 299f94b | 2017-07-28 17:16:36 -0500 | [diff] [blame] | 202 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 203 | The canonical hostname where the project lives. E.g., |
| 204 | `git.example.com`. |
Monty Taylor | 299f94b | 2017-07-28 17:16:36 -0500 | [diff] [blame] | 205 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 206 | .. var:: canonical_name |
| 207 | |
| 208 | The full canonical name of the project including hostname. |
| 209 | E.g., `git.example.com/org/project`. |
| 210 | |
Monty Taylor | 9e67bb7 | 2017-08-08 15:32:06 -0500 | [diff] [blame] | 211 | .. var:: src_dir |
| 212 | |
James E. Blair | ba46c06 | 2017-08-28 16:23:24 -0700 | [diff] [blame] | 213 | The path to the source code relative to the work dir. E.g., |
| 214 | `src/git.example.com/org/project`. |
Monty Taylor | 9e67bb7 | 2017-08-08 15:32:06 -0500 | [diff] [blame] | 215 | |
James E. Blair | ba46c06 | 2017-08-28 16:23:24 -0700 | [diff] [blame] | 216 | .. var:: projects |
| 217 | :type: list |
| 218 | |
| 219 | A list of all projects prepared by Zuul for the item. It |
| 220 | includes, at least, the item's own project. It also includes |
| 221 | the projects of any items this item depends on, as well as the |
| 222 | projects that appear in :attr:`job.required-projects`. |
| 223 | |
| 224 | This is a list of dictionaries, with each element consisting of: |
| 225 | |
| 226 | .. var:: name |
| 227 | |
| 228 | The name of the project, excluding hostname. E.g., `org/project`. |
| 229 | |
| 230 | .. var:: short_name |
| 231 | |
| 232 | The name of the project, excluding directories or |
| 233 | organizations. E.g., `project`. |
| 234 | |
| 235 | .. var:: canonical_hostname |
| 236 | |
| 237 | The canonical hostname where the project lives. E.g., |
| 238 | `git.example.com`. |
| 239 | |
| 240 | .. var:: canonical_name |
| 241 | |
| 242 | The full canonical name of the project including hostname. |
| 243 | E.g., `git.example.com/org/project`. |
| 244 | |
| 245 | .. var:: src_dir |
| 246 | |
| 247 | The path to the source code, relative to the work dir. E.g., |
| 248 | `src/git.example.com/org/project`. |
Monty Taylor | 9e67bb7 | 2017-08-08 15:32:06 -0500 | [diff] [blame] | 249 | |
James E. Blair | b3d3f2b | 2017-09-27 12:04:55 -0700 | [diff] [blame] | 250 | .. var:: required |
| 251 | |
| 252 | A boolean indicating whether this project appears in the |
| 253 | :attr:`job.required-projects` list for this job. |
| 254 | |
Ian Wienand | d61d98e | 2017-10-18 08:21:19 +1100 | [diff] [blame] | 255 | .. var:: _projects |
| 256 | :type: dict |
| 257 | |
| 258 | The same as ``projects`` but a dictionary indexed by the |
| 259 | ``name`` value of each entry. ``projects`` will be converted to |
| 260 | this. |
| 261 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 262 | .. var:: tenant |
| 263 | |
| 264 | The name of the current Zuul tenant. |
| 265 | |
James E. Blair | 93e57f7 | 2017-09-01 08:51:49 -0700 | [diff] [blame] | 266 | .. var:: timeout |
| 267 | |
| 268 | The job timeout, in seconds. |
| 269 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 270 | .. var:: jobtags |
| 271 | |
| 272 | A list of tags associated with the job. Not to be confused with |
| 273 | git tags, these are simply free-form text fields that can be |
| 274 | used by the job for reporting or classification purposes. |
| 275 | |
| 276 | .. var:: items |
| 277 | :type: list |
| 278 | |
| 279 | A list of dictionaries, each representing an item being tested |
| 280 | with this change with the format: |
| 281 | |
| 282 | .. var:: project |
| 283 | |
| 284 | The item's project. This is a data structure with the |
| 285 | following fields: |
| 286 | |
| 287 | .. var:: name |
| 288 | |
| 289 | The name of the project, excluding hostname. E.g., |
| 290 | `org/project`. |
| 291 | |
| 292 | .. var:: short_name |
| 293 | |
| 294 | The name of the project, excluding directories or |
| 295 | organizations. E.g., `project`. |
| 296 | |
| 297 | .. var:: canonical_hostname |
| 298 | |
| 299 | The canonical hostname where the project lives. E.g., |
| 300 | `git.example.com`. |
| 301 | |
| 302 | .. var:: canonical_name |
| 303 | |
| 304 | The full canonical name of the project including hostname. |
| 305 | E.g., `git.example.com/org/project`. |
| 306 | |
Monty Taylor | 9e67bb7 | 2017-08-08 15:32:06 -0500 | [diff] [blame] | 307 | .. var:: src_dir |
| 308 | |
| 309 | The path to the source code on the remote host, relative |
| 310 | to the home dir of the remote user. |
| 311 | E.g., `src/git.example.com/org/project`. |
| 312 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 313 | .. var:: branch |
| 314 | |
| 315 | The target branch of the change (without the `refs/heads/` prefix). |
| 316 | |
| 317 | .. var:: change |
| 318 | |
| 319 | The identifier for the change. |
| 320 | |
Monty Taylor | 4163444 | 2017-09-06 18:35:17 -0500 | [diff] [blame] | 321 | .. var:: change_url |
| 322 | |
| 323 | The URL to the source location of the given change. |
| 324 | E.g., `https://review.example.org/#/c/123456/` or |
| 325 | `https://github.com/example/example/pull/1234`. |
| 326 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 327 | .. var:: patchset |
| 328 | |
| 329 | The patchset identifier for the change. If a change is |
| 330 | revised, this will have a different value. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 331 | |
Jesse Keating | a49ddaf | 2017-09-11 18:17:47 -0600 | [diff] [blame] | 332 | .. var:: zuul_success |
| 333 | |
| 334 | Post run playbook(s) will be passed this variable to indicate if the run |
| 335 | phase of the job was successful or not. This variable is meant to be used |
| 336 | with the `boolean` filter. |
| 337 | |
| 338 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 339 | Change Items |
| 340 | ++++++++++++ |
| 341 | |
| 342 | A change to the repository. Most often, this will be a git reference |
| 343 | which has not yet been merged into the repository (e.g., a gerrit |
| 344 | change or a GitHub pull request). The following additional variables |
| 345 | are available: |
| 346 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 347 | .. var:: zuul |
| 348 | :hidden: |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 349 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 350 | .. var:: branch |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 351 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 352 | The target branch of the change (without the `refs/heads/` prefix). |
| 353 | |
| 354 | .. var:: change |
| 355 | |
| 356 | The identifier for the change. |
| 357 | |
| 358 | .. var:: patchset |
| 359 | |
| 360 | The patchset identifier for the change. If a change is revised, |
| 361 | this will have a different value. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 362 | |
Monty Taylor | 4163444 | 2017-09-06 18:35:17 -0500 | [diff] [blame] | 363 | .. var:: change_url |
| 364 | |
| 365 | The URL to the source location of the given change. |
| 366 | E.g., `https://review.example.org/#/c/123456/` or |
| 367 | `https://github.com/example/example/pull/1234`. |
| 368 | |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 369 | Branch Items |
| 370 | ++++++++++++ |
| 371 | |
| 372 | This represents a branch tip. This item may have been enqueued |
| 373 | because the branch was updated (via a change having merged, or a |
| 374 | direct push). Or it may have been enqueued by a timer for the purpose |
| 375 | of verifying the current condition of the branch. The following |
| 376 | additional variables are available: |
| 377 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 378 | .. var:: zuul |
| 379 | :hidden: |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 380 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 381 | .. var:: branch |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 382 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 383 | The name of the item's branch (without the `refs/heads/` |
| 384 | prefix). |
| 385 | |
| 386 | .. var:: oldrev |
| 387 | |
| 388 | If the item was enqueued as the result of a change merging or |
| 389 | being pushed to the branch, the git sha of the old revision will |
| 390 | be included here. Otherwise, this variable will be undefined. |
| 391 | |
| 392 | .. var:: newrev |
| 393 | |
| 394 | If the item was enqueued as the result of a change merging or |
| 395 | being pushed to the branch, the git sha of the new revision will |
| 396 | be included here. Otherwise, this variable will be undefined. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 397 | |
| 398 | Tag Items |
| 399 | +++++++++ |
| 400 | |
| 401 | This represents a git tag. The item may have been enqueued because a |
| 402 | tag was created or deleted. The following additional variables are |
| 403 | available: |
| 404 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 405 | .. var:: zuul |
| 406 | :hidden: |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 407 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 408 | .. var:: tag |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 409 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 410 | The name of the item's tag (without the `refs/tags/` prefix). |
| 411 | |
| 412 | .. var:: oldrev |
| 413 | |
| 414 | If the item was enqueued as the result of a tag being deleted, |
| 415 | the previous git sha of the tag will be included here. If the |
| 416 | tag was created, this variable will be undefined. |
| 417 | |
| 418 | .. var:: newrev |
| 419 | |
| 420 | If the item was enqueued as the result of a tag being created, |
| 421 | the new git sha of the tag will be included here. If the tag |
| 422 | was deleted, this variable will be undefined. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 423 | |
| 424 | Ref Items |
| 425 | +++++++++ |
| 426 | |
| 427 | This represents a git reference that is neither a change, branch, or |
| 428 | tag. Note that all items include a `ref` attribute which may be used |
| 429 | to identify the ref. The following additional variables are |
| 430 | available: |
| 431 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 432 | .. var:: zuul |
| 433 | :hidden: |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 434 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 435 | .. var:: oldrev |
| 436 | |
| 437 | If the item was enqueued as the result of a ref being deleted, |
| 438 | the previous git sha of the ref will be included here. If the |
| 439 | ref was created, this variable will be undefined. |
| 440 | |
| 441 | .. var:: newrev |
| 442 | |
| 443 | If the item was enqueued as the result of a ref being created, |
| 444 | the new git sha of the ref will be included here. If the ref |
| 445 | was deleted, this variable will be undefined. |
James E. Blair | 2103778 | 2017-07-19 11:56:55 -0700 | [diff] [blame] | 446 | |
| 447 | Working Directory |
| 448 | +++++++++++++++++ |
| 449 | |
| 450 | Additionally, some information about the working directory and the |
| 451 | executor running the job is available: |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 452 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 453 | .. var:: zuul |
| 454 | :hidden: |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 455 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 456 | .. var:: executor |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 457 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 458 | A number of values related to the executor running the job are |
| 459 | available: |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 460 | |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 461 | .. var:: hostname |
| 462 | |
| 463 | The hostname of the executor. |
| 464 | |
| 465 | .. var:: src_root |
| 466 | |
| 467 | The path to the source directory. |
| 468 | |
| 469 | .. var:: log_root |
| 470 | |
| 471 | The path to the logs directory. |
| 472 | |
| 473 | .. var:: work_root |
| 474 | |
| 475 | The path to the working directory. |
Jamie Lennox | 7655b55 | 2017-03-17 12:33:38 +1100 | [diff] [blame] | 476 | |
| 477 | .. _user_sitewide_variables: |
| 478 | |
| 479 | Site-wide Variables |
| 480 | ~~~~~~~~~~~~~~~~~~~ |
| 481 | |
| 482 | The Zuul administrator may define variables which will be available to |
| 483 | all jobs running in the system. These are statically defined and may |
| 484 | not be altered by jobs. See the :ref:`Administrator's Guide |
| 485 | <admin_sitewide_variables>` for information on how a site |
| 486 | administrator may define these variables. |
| 487 | |
James E. Blair | 698703c | 2017-09-15 20:58:30 -0600 | [diff] [blame] | 488 | Parent Job Results |
| 489 | ~~~~~~~~~~~~~~~~~~ |
| 490 | |
| 491 | A job may return data to Zuul for later use by jobs which depend on |
| 492 | it. For details, see :ref:`return_values`. |
Jamie Lennox | 7655b55 | 2017-03-17 12:33:38 +1100 | [diff] [blame] | 493 | |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 494 | SSH Keys |
| 495 | -------- |
| 496 | |
| 497 | Zuul starts each job with an SSH agent running and the key used to |
| 498 | access the job's nodes added to that agent. Generally you won't need |
| 499 | to be aware of this since Ansible will use this when performing any |
| 500 | tasks on remote nodes. However, under some circumstances you may want |
| 501 | to interact with the agent. For example, you may wish to add a key |
| 502 | provided as a secret to the job in order to access a specific host, or |
| 503 | you may want to, in a pre-playbook, replace the key used to log into |
| 504 | the assigned nodes in order to further protect it from being abused by |
| 505 | untrusted job content. |
| 506 | |
| 507 | .. TODO: describe standard lib and link to published docs for it. |
| 508 | |
James E. Blair | 88e79c0 | 2017-07-07 13:36:54 -0700 | [diff] [blame] | 509 | .. _return_values: |
| 510 | |
James E. Blair | 196f61a | 2017-06-30 15:42:29 -0700 | [diff] [blame] | 511 | Return Values |
| 512 | ------------- |
| 513 | |
James E. Blair | 698703c | 2017-09-15 20:58:30 -0600 | [diff] [blame] | 514 | A job may return some values to Zuul to affect its behavior and for |
| 515 | use by other jobs.. To return a value, use the ``zuul_return`` |
| 516 | Ansible module in a job playbook. For example: |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 517 | |
| 518 | .. code-block:: yaml |
James E. Blair | 196f61a | 2017-06-30 15:42:29 -0700 | [diff] [blame] | 519 | |
| 520 | tasks: |
| 521 | - zuul_return: |
| 522 | data: |
| 523 | foo: bar |
| 524 | |
James E. Blair | 698703c | 2017-09-15 20:58:30 -0600 | [diff] [blame] | 525 | Will return the dictionary ``{'foo': 'bar'}`` to Zuul. |
James E. Blair | 196f61a | 2017-06-30 15:42:29 -0700 | [diff] [blame] | 526 | |
| 527 | .. TODO: xref to section describing formatting |
| 528 | |
James E. Blair | 698703c | 2017-09-15 20:58:30 -0600 | [diff] [blame] | 529 | To set the log URL for a build, use *zuul_return* to set the |
James E. Blair | d9f0efb | 2017-08-02 16:07:44 -0700 | [diff] [blame] | 530 | **zuul.log_url** value. For example: |
| 531 | |
| 532 | .. code-block:: yaml |
James E. Blair | 196f61a | 2017-06-30 15:42:29 -0700 | [diff] [blame] | 533 | |
| 534 | tasks: |
| 535 | - zuul_return: |
| 536 | data: |
| 537 | zuul: |
| 538 | log_url: http://logs.example.com/path/to/build/logs |
James E. Blair | 698703c | 2017-09-15 20:58:30 -0600 | [diff] [blame] | 539 | |
| 540 | Any values other than those in the ``zuul`` hierarchy will be supplied |
| 541 | as Ansible variables to child jobs. These variables have less |
| 542 | precedence than any other type of variable in Zuul, so be sure their |
| 543 | names are not shared by any job variables. If more than one parent |
| 544 | job returns the same variable, the value from the later job in the job |
| 545 | graph will take precedence. |