James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 1 | :title: Gerrit Driver |
| 2 | |
| 3 | Gerrit |
| 4 | ====== |
| 5 | |
| 6 | `Gerrit`_ is a code review system. The Gerrit driver supports |
| 7 | sources, triggers, and reporters. |
| 8 | |
| 9 | .. _Gerrit: https://www.gerritcodereview.com/ |
| 10 | |
| 11 | Zuul will need access to a Gerrit user. |
| 12 | |
| 13 | Create an SSH keypair for Zuul to use if there isn't one already, and |
| 14 | create a Gerrit user with that key:: |
| 15 | |
| 16 | cat ~/id_rsa.pub | ssh -p29418 review.example.com gerrit create-account --ssh-key - --full-name Zuul zuul |
| 17 | |
| 18 | Give that user whatever permissions will be needed on the projects you |
| 19 | want Zuul to report on. For instance, you may want to grant |
| 20 | ``Verified +/-1`` and ``Submit`` to the user. Additional categories |
| 21 | or values may be added to Gerrit. Zuul is very flexible and can take |
| 22 | advantage of those. |
| 23 | |
| 24 | Connection Configuration |
| 25 | ------------------------ |
| 26 | |
| 27 | The supported options in zuul.conf connections are: |
| 28 | |
| 29 | **driver=gerrit** |
| 30 | |
| 31 | **server** |
| 32 | FQDN of Gerrit server. |
| 33 | ``server=review.example.com`` |
| 34 | |
| 35 | **canonical_hostname** |
| 36 | The canonical hostname associated with the git repos on the Gerrit |
| 37 | server. Defaults to the value of **server**. This is used to |
James E. Blair | cc3ca7d | 2017-06-29 11:09:18 -0700 | [diff] [blame] | 38 | identify projects from this connection by name and in preparing |
| 39 | repos on the filesystem for use by jobs. Note that Zuul will still |
| 40 | only communicate with the Gerrit server identified by **server**; |
| 41 | this option is useful if users customarily use a different hostname |
| 42 | to clone or pull git repos so that when Zuul places them in the |
| 43 | job's working directory, they appear under this directory name. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 44 | ``canonical_hostname=git.example.com`` |
| 45 | |
| 46 | **port** |
| 47 | Optional: Gerrit server port. |
| 48 | ``port=29418`` |
| 49 | |
| 50 | **baseurl** |
| 51 | Optional: path to Gerrit web interface. Defaults to ``https://<value |
| 52 | of server>/``. ``baseurl=https://review.example.com/review_site/`` |
| 53 | |
| 54 | **user** |
| 55 | User name to use when logging into above server via ssh. |
| 56 | ``user=zuul`` |
| 57 | |
| 58 | **sshkey** |
| 59 | Path to SSH key to use when logging into above server. |
| 60 | ``sshkey=/home/zuul/.ssh/id_rsa`` |
| 61 | |
| 62 | **keepalive** |
| 63 | Optional: Keepalive timeout, 0 means no keepalive. |
| 64 | ``keepalive=60`` |
| 65 | |
| 66 | Trigger Configuration |
| 67 | --------------------- |
| 68 | |
| 69 | Zuul works with standard versions of Gerrit by invoking the ``gerrit |
| 70 | stream-events`` command over an SSH connection. It also reports back |
| 71 | to Gerrit using SSH. |
| 72 | |
| 73 | If using Gerrit 2.7 or later, make sure the user is a member of a group |
| 74 | that is granted the ``Stream Events`` permission, otherwise it will not |
| 75 | be able to invoke the ``gerrit stream-events`` command over SSH. |
| 76 | |
| 77 | The supported pipeline trigger options are: |
| 78 | |
| 79 | **event** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 80 | The event name from gerrit. Examples: ``patchset-created``, |
| 81 | ``comment-added``, ``ref-updated``. This field is treated as a |
| 82 | regular expression. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 83 | |
| 84 | **branch** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 85 | The branch associated with the event. Example: ``master``. This |
| 86 | field is treated as a regular expression, and multiple branches may |
| 87 | be listed. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 88 | |
| 89 | **ref** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 90 | On ref-updated events, the branch parameter is not used, instead the |
| 91 | ref is provided. Currently Gerrit has the somewhat idiosyncratic |
| 92 | behavior of specifying bare refs for branch names (e.g., |
| 93 | ``master``), but full ref names for other kinds of refs (e.g., |
| 94 | ``refs/tags/foo``). Zuul matches what you put here exactly against |
| 95 | what Gerrit provides. This field is treated as a regular |
| 96 | expression, and multiple refs may be listed. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 97 | |
| 98 | **ignore-deletes** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 99 | When a branch is deleted, a ref-updated event is emitted with a |
| 100 | newrev of all zeros specified. The ``ignore-deletes`` field is a |
| 101 | boolean value that describes whether or not these newrevs trigger |
| 102 | ref-updated events. The default is True, which will not trigger |
| 103 | ref-updated events. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 104 | |
| 105 | **approval** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 106 | This is only used for ``comment-added`` events. It only matches if |
| 107 | the event has a matching approval associated with it. Example: |
James E. Blair | b4fc8ac | 2017-07-28 10:44:32 -0700 | [diff] [blame] | 108 | ``Code-Review: 2`` matches a ``+2`` vote on the code review |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 109 | category. Multiple approvals may be listed. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 110 | |
| 111 | **email** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 112 | This is used for any event. It takes a regex applied on the |
| 113 | performer email, i.e. Gerrit account email address. If you want to |
| 114 | specify several email filters, you must use a YAML list. Make sure |
| 115 | to use non greedy matchers and to escapes dots! Example: ``email: |
| 116 | ^.*?@example\.org$``. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 117 | |
| 118 | **email_filter** (deprecated) |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 119 | A deprecated alternate spelling of *email*. Only one of *email* or |
| 120 | *email_filter* should be used. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 121 | |
| 122 | **username** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 123 | This is used for any event. It takes a regex applied on the |
| 124 | performer username, i.e. Gerrit account name. If you want to |
| 125 | specify several username filters, you must use a YAML list. Make |
| 126 | sure to use non greedy matchers and to escapes dots! Example: |
| 127 | ``username: ^jenkins$``. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 128 | |
| 129 | **username_filter** (deprecated) |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 130 | A deprecated alternate spelling of *username*. Only one of |
| 131 | *username* or *username_filter* should be used. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 132 | |
| 133 | **comment** |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 134 | This is only used for ``comment-added`` events. It accepts a list |
| 135 | of regexes that are searched for in the comment string. If any of |
| 136 | these regexes matches a portion of the comment string the trigger is |
| 137 | matched. ``comment: retrigger`` will match when comments containing |
| 138 | 'retrigger' somewhere in the comment text are added to a change. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 139 | |
| 140 | **comment_filter** (deprecated) |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 141 | A deprecated alternate spelling of *comment*. Only one of *comment* |
| 142 | or *comment_filter* should be used. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 143 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 144 | **require-approval** |
| 145 | This may be used for any event. It requires that a certain kind of |
| 146 | approval be present for the current patchset of the change (the |
| 147 | approval could be added by the event in question). It follows the |
James E. Blair | 91fe483 | 2017-07-28 17:28:26 -0700 | [diff] [blame^] | 148 | same syntax as :attr:`pipeline.require.<gerrit |
| 149 | source>.approval`. For each specified criteria there must exist a |
| 150 | matching approval. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 151 | |
James E. Blair | 88e5388 | 2017-06-23 21:45:07 +0100 | [diff] [blame] | 152 | **reject-approval** |
| 153 | This takes a list of approvals in the same format as |
| 154 | *require-approval* but will fail to enter the pipeline if there is a |
| 155 | matching approval. |
James E. Blair | eff5a9d | 2017-06-20 00:00:37 -0700 | [diff] [blame] | 156 | |
| 157 | Reporter Configuration |
| 158 | ---------------------- |
| 159 | |
| 160 | Zuul works with standard versions of Gerrit by invoking the |
| 161 | ``gerrit`` command over an SSH connection. It reports back to |
| 162 | Gerrit using SSH. |
| 163 | |
| 164 | The dictionary passed to the Gerrit reporter is used for ``gerrit |
| 165 | review`` arguments, with the boolean value of ``true`` simply |
| 166 | indicating that the argument should be present without following it |
| 167 | with a value. For example, ``verified: 1`` becomes ``gerrit review |
| 168 | --verified 1`` and ``submit: true`` becomes ``gerrit review |
| 169 | --submit``. |
| 170 | |
| 171 | A :ref:`connection<connections>` that uses the gerrit driver must be |
| 172 | supplied to the trigger. |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 173 | |
| 174 | Requirements Configuration |
| 175 | -------------------------- |
| 176 | |
| 177 | As described in :ref:`pipeline.require <pipeline-require>` and |
| 178 | :ref:`pipeline.reject <pipeline-reject>`, pipelines may specify that |
| 179 | items meet certain conditions in order to be enqueued into the |
| 180 | pipeline. These conditions vary according to the source of the |
| 181 | project in question. To supply requirements for changes from a Gerrit |
James E. Blair | b4fc8ac | 2017-07-28 10:44:32 -0700 | [diff] [blame] | 182 | source named *my-gerrit*, create a configuration such as the |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 183 | following:: |
| 184 | |
| 185 | pipeline: |
| 186 | require: |
| 187 | my-gerrit: |
| 188 | approval: |
James E. Blair | b4fc8ac | 2017-07-28 10:44:32 -0700 | [diff] [blame] | 189 | - Code-Review: 2 |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 190 | |
| 191 | This indicates that changes originating from the Gerrit connection |
| 192 | named *my-gerrit* must have a Code Review vote of +2 in order to be |
| 193 | enqueued into the pipeline. |
| 194 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 195 | .. attr:: pipeline.require.<gerrit source> |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 196 | |
| 197 | The dictionary passed to the Gerrit pipeline `require` attribute |
| 198 | supports the following attributes: |
| 199 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 200 | .. attr:: approval |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 201 | |
| 202 | This requires that a certain kind of approval be present for the |
| 203 | current patchset of the change (the approval could be added by |
| 204 | the event in question). It takes several sub-parameters, all of |
| 205 | which are optional and are combined together so that there must |
| 206 | be an approval matching all specified requirements. |
| 207 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 208 | .. attr:: username |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 209 | |
| 210 | If present, an approval from this username is required. It is |
| 211 | treated as a regular expression. |
| 212 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 213 | .. attr:: email |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 214 | |
| 215 | If present, an approval with this email address is required. It is |
| 216 | treated as a regular expression. |
| 217 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 218 | .. attr:: older-than |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 219 | |
| 220 | If present, the approval must be older than this amount of time |
| 221 | to match. Provide a time interval as a number with a suffix of |
| 222 | "w" (weeks), "d" (days), "h" (hours), "m" (minutes), "s" |
| 223 | (seconds). Example ``48h`` or ``2d``. |
| 224 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 225 | .. attr:: newer-than |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 226 | |
| 227 | If present, the approval must be newer than this amount |
| 228 | of time to match. Same format as "older-than". |
| 229 | |
| 230 | Any other field is interpreted as a review category and value |
| 231 | pair. For example ``Verified: 1`` would require that the |
| 232 | approval be for a +1 vote in the "Verified" column. The value |
| 233 | may either be a single value or a list: ``Verified: [1, 2]`` |
| 234 | would match either a +1 or +2 vote. |
| 235 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 236 | .. attr:: open |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 237 | |
| 238 | A boolean value (``true`` or ``false``) that indicates whether |
| 239 | the change must be open or closed in order to be enqueued. |
| 240 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 241 | .. attr:: current-patchset |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 242 | |
| 243 | A boolean value (``true`` or ``false``) that indicates whether the |
| 244 | change must be the current patchset in order to be enqueued. |
| 245 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 246 | .. attr:: status |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 247 | |
| 248 | A string value that corresponds with the status of the change |
| 249 | reported by the trigger. |
| 250 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 251 | .. attr:: pipeline.reject.<gerrit source> |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 252 | |
| 253 | The `reject` attribute is the mirror of the `require` attribute. It |
| 254 | also accepts a dictionary under the connection name. This |
| 255 | dictionary supports the following attributes: |
| 256 | |
James E. Blair | 9437591 | 2017-07-28 17:20:27 -0700 | [diff] [blame] | 257 | .. attr:: approval |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 258 | |
| 259 | This takes a list of approvals. If an approval matches the |
| 260 | provided criteria the change can not be entered into the |
James E. Blair | 91fe483 | 2017-07-28 17:28:26 -0700 | [diff] [blame^] | 261 | pipeline. It follows the same syntax as |
| 262 | :attr:`pipeline.require.<gerrit source>.approval`. |
James E. Blair | d134c6d | 2017-07-26 16:09:34 -0700 | [diff] [blame] | 263 | |
| 264 | Example to reject a change with any negative vote:: |
| 265 | |
| 266 | reject: |
| 267 | my-gerrit: |
| 268 | approval: |
James E. Blair | b4fc8ac | 2017-07-28 10:44:32 -0700 | [diff] [blame] | 269 | - Code-Review: [-1, -2] |