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