blob: 935cb329010ffa2adee16bd218564fa4e2affd8e [file] [log] [blame]
James E. Blaireff5a9d2017-06-20 00:00:37 -07001:title: Gerrit Driver
2
3Gerrit
4======
5
6`Gerrit`_ is a code review system. The Gerrit driver supports
7sources, triggers, and reporters.
8
9.. _Gerrit: https://www.gerritcodereview.com/
10
11Zuul will need access to a Gerrit user.
12
13Create an SSH keypair for Zuul to use if there isn't one already, and
14create 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
18Give that user whatever permissions will be needed on the projects you
19want Zuul to report on. For instance, you may want to grant
20``Verified +/-1`` and ``Submit`` to the user. Additional categories
21or values may be added to Gerrit. Zuul is very flexible and can take
22advantage of those.
23
24Connection Configuration
25------------------------
26
James E. Blaird23f45d2017-08-03 16:37:13 -070027The supported options in ``zuul.conf`` connections are:
James E. Blaireff5a9d2017-06-20 00:00:37 -070028
James E. Blaird23f45d2017-08-03 16:37:13 -070029.. attr:: <gerrit connection>
James E. Blaireff5a9d2017-06-20 00:00:37 -070030
James E. Blaird23f45d2017-08-03 16:37:13 -070031 .. attr:: driver
32 :required:
James E. Blaireff5a9d2017-06-20 00:00:37 -070033
James E. Blaird23f45d2017-08-03 16:37:13 -070034 .. value:: gerrit
James E. Blaireff5a9d2017-06-20 00:00:37 -070035
James E. Blaird23f45d2017-08-03 16:37:13 -070036 The connection must set ``driver=gerrit`` for Gerrit connections.
James E. Blaireff5a9d2017-06-20 00:00:37 -070037
James E. Blaird23f45d2017-08-03 16:37:13 -070038 .. attr:: server
James E. Blaireff5a9d2017-06-20 00:00:37 -070039
James E. Blaird23f45d2017-08-03 16:37:13 -070040 Fully qualified domain name of Gerrit server.
James E. Blaireff5a9d2017-06-20 00:00:37 -070041
James E. Blaird23f45d2017-08-03 16:37:13 -070042 .. attr:: canonical_hostname
James E. Blaireff5a9d2017-06-20 00:00:37 -070043
James E. Blaird23f45d2017-08-03 16:37:13 -070044 The canonical hostname associated with the git repos on the
45 Gerrit server. Defaults to the value of
46 :attr:`<gerrit connection>.server`. This is used to identify
47 projects from this connection by name and in preparing repos on
48 the filesystem for use by jobs. Note that Zuul will still only
49 communicate with the Gerrit server identified by ``server``;
50 this option is useful if users customarily use a different
51 hostname to clone or pull git repos so that when Zuul places
52 them in the job's working directory, they appear under this
53 directory name.
54
55 .. attr:: port
56 :default: 29418
57
58 Gerrit server port.
59
60 .. attr:: baseurl
61
62 Path to Gerrit web interface.
63
Clark Boylana7f724c2017-10-25 11:35:19 -070064 .. attr:: gitweb_url_template
65 :default: {baseurl}/gitweb?p={project.name}.git;a=commitdiff;h={sha}
66
67 Url template for links to specific git shas. By default this will
68 point at Gerrit's built in gitweb but you can customize this value
69 to point elsewhere (like cgit or github).
70
71 The three values available for string interpolation are baseurl
72 which points back to Gerrit, project and all of its safe attributes,
73 and sha which is the git sha1.
74
James E. Blaird23f45d2017-08-03 16:37:13 -070075 .. attr:: user
76 :default: zuul
77
78 User name to use when logging into Gerrit via ssh.
79
80 .. attr:: sshkey
81 :default: ~zuul/.ssh/id_rsa
82
83 Path to SSH key to use when logging into Gerrit.
84
85 .. attr:: keepalive
86 :default: 60
87
88 SSH connection keepalive timeout; ``0`` disables.
James E. Blaireff5a9d2017-06-20 00:00:37 -070089
90Trigger Configuration
91---------------------
92
93Zuul works with standard versions of Gerrit by invoking the ``gerrit
94stream-events`` command over an SSH connection. It also reports back
95to Gerrit using SSH.
96
97If using Gerrit 2.7 or later, make sure the user is a member of a group
98that is granted the ``Stream Events`` permission, otherwise it will not
99be able to invoke the ``gerrit stream-events`` command over SSH.
100
James E. Blaird23f45d2017-08-03 16:37:13 -0700101.. attr:: pipeline.trigger.<gerrit source>
James E. Blaireff5a9d2017-06-20 00:00:37 -0700102
James E. Blair02157ad2017-08-03 17:34:22 -0700103 The dictionary passed to the Gerrit pipeline ``trigger`` attribute
James E. Blaird23f45d2017-08-03 16:37:13 -0700104 supports the following attributes:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700105
James E. Blaird23f45d2017-08-03 16:37:13 -0700106 .. attr:: event
107 :required:
James E. Blaireff5a9d2017-06-20 00:00:37 -0700108
James E. Blaird23f45d2017-08-03 16:37:13 -0700109 The event name from gerrit. Examples: ``patchset-created``,
110 ``comment-added``, ``ref-updated``. This field is treated as a
111 regular expression.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700112
James E. Blaird23f45d2017-08-03 16:37:13 -0700113 .. attr:: branch
James E. Blaireff5a9d2017-06-20 00:00:37 -0700114
James E. Blaird23f45d2017-08-03 16:37:13 -0700115 The branch associated with the event. Example: ``master``.
116 This field is treated as a regular expression, and multiple
117 branches may be listed.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700118
James E. Blaird23f45d2017-08-03 16:37:13 -0700119 .. attr:: ref
James E. Blaireff5a9d2017-06-20 00:00:37 -0700120
James E. Blaird23f45d2017-08-03 16:37:13 -0700121 On ref-updated events, the branch parameter is not used, instead
122 the ref is provided. Currently Gerrit has the somewhat
123 idiosyncratic behavior of specifying bare refs for branch names
124 (e.g., ``master``), but full ref names for other kinds of refs
125 (e.g., ``refs/tags/foo``). Zuul matches this value exactly
126 against what Gerrit provides. This field is treated as a
127 regular expression, and multiple refs may be listed.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700128
James E. Blaird23f45d2017-08-03 16:37:13 -0700129 .. attr:: ignore-deletes
130 :default: true
James E. Blaireff5a9d2017-06-20 00:00:37 -0700131
James E. Blaird23f45d2017-08-03 16:37:13 -0700132 When a branch is deleted, a ref-updated event is emitted with a
133 newrev of all zeros specified. The ``ignore-deletes`` field is a
134 boolean value that describes whether or not these newrevs
135 trigger ref-updated events.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700136
James E. Blaird23f45d2017-08-03 16:37:13 -0700137 .. attr:: approval
James E. Blaireff5a9d2017-06-20 00:00:37 -0700138
James E. Blaird23f45d2017-08-03 16:37:13 -0700139 This is only used for ``comment-added`` events. It only matches
140 if the event has a matching approval associated with it.
141 Example: ``Code-Review: 2`` matches a ``+2`` vote on the code
142 review category. Multiple approvals may be listed.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700143
James E. Blaird23f45d2017-08-03 16:37:13 -0700144 .. attr:: email
James E. Blaireff5a9d2017-06-20 00:00:37 -0700145
James E. Blaird23f45d2017-08-03 16:37:13 -0700146 This is used for any event. It takes a regex applied on the
147 performer email, i.e. Gerrit account email address. If you want
148 to specify several email filters, you must use a YAML list.
149 Make sure to use non greedy matchers and to escapes dots!
150 Example: ``email: ^.*?@example\.org$``.
151
152 .. attr:: username
153
154 This is used for any event. It takes a regex applied on the
155 performer username, i.e. Gerrit account name. If you want to
156 specify several username filters, you must use a YAML list.
157 Make sure to use non greedy matchers and to escapes dots.
158 Example: ``username: ^zuul$``.
159
160 .. attr:: comment
161
162 This is only used for ``comment-added`` events. It accepts a
163 list of regexes that are searched for in the comment string. If
164 any of these regexes matches a portion of the comment string the
165 trigger is matched. ``comment: retrigger`` will match when
166 comments containing ``retrigger`` somewhere in the comment text
167 are added to a change.
168
169 .. attr:: require-approval
170
171 This may be used for any event. It requires that a certain kind
172 of approval be present for the current patchset of the change
173 (the approval could be added by the event in question). It
174 follows the same syntax as :attr:`pipeline.require.<gerrit
175 source>.approval`. For each specified criteria there must exist
176 a matching approval.
177
178 .. attr:: reject-approval
179
180 This takes a list of approvals in the same format as
181 :attr:`pipeline.trigger.<gerrit source>.require-approval` but
182 will fail to enter the pipeline if there is a matching approval.
James E. Blaireff5a9d2017-06-20 00:00:37 -0700183
184Reporter Configuration
185----------------------
186
187Zuul works with standard versions of Gerrit by invoking the
188``gerrit`` command over an SSH connection. It reports back to
189Gerrit using SSH.
190
191The dictionary passed to the Gerrit reporter is used for ``gerrit
192review`` arguments, with the boolean value of ``true`` simply
193indicating that the argument should be present without following it
194with a value. For example, ``verified: 1`` becomes ``gerrit review
195--verified 1`` and ``submit: true`` becomes ``gerrit review
196--submit``.
197
198A :ref:`connection<connections>` that uses the gerrit driver must be
199supplied to the trigger.
James E. Blaird134c6d2017-07-26 16:09:34 -0700200
201Requirements Configuration
202--------------------------
203
James E. Blair32c52482017-07-29 07:49:03 -0700204As described in :attr:`pipeline.require` and :attr:`pipeline.reject`,
205pipelines may specify that items meet certain conditions in order to
206be enqueued into the pipeline. These conditions vary according to the
207source of the project in question. To supply requirements for changes
James E. Blaird23f45d2017-08-03 16:37:13 -0700208from a Gerrit source named ``my-gerrit``, create a configuration such
209as the following:
James E. Blaird134c6d2017-07-26 16:09:34 -0700210
James E. Blaird23f45d2017-08-03 16:37:13 -0700211.. code-block:: yaml
212
213 pipeline:
214 require:
215 my-gerrit:
216 approval:
217 - Code-Review: 2
James E. Blaird134c6d2017-07-26 16:09:34 -0700218
219This indicates that changes originating from the Gerrit connection
James E. Blaird23f45d2017-08-03 16:37:13 -0700220named ``my-gerrit`` must have a ``Code-Review`` vote of ``+2`` in
221order to be enqueued into the pipeline.
James E. Blaird134c6d2017-07-26 16:09:34 -0700222
James E. Blair94375912017-07-28 17:20:27 -0700223.. attr:: pipeline.require.<gerrit source>
James E. Blaird134c6d2017-07-26 16:09:34 -0700224
225 The dictionary passed to the Gerrit pipeline `require` attribute
226 supports the following attributes:
227
James E. Blair94375912017-07-28 17:20:27 -0700228 .. attr:: approval
James E. Blaird134c6d2017-07-26 16:09:34 -0700229
230 This requires that a certain kind of approval be present for the
231 current patchset of the change (the approval could be added by
232 the event in question). It takes several sub-parameters, all of
233 which are optional and are combined together so that there must
234 be an approval matching all specified requirements.
235
James E. Blair94375912017-07-28 17:20:27 -0700236 .. attr:: username
James E. Blaird134c6d2017-07-26 16:09:34 -0700237
238 If present, an approval from this username is required. It is
239 treated as a regular expression.
240
James E. Blair94375912017-07-28 17:20:27 -0700241 .. attr:: email
James E. Blaird134c6d2017-07-26 16:09:34 -0700242
243 If present, an approval with this email address is required. It is
244 treated as a regular expression.
245
James E. Blair94375912017-07-28 17:20:27 -0700246 .. attr:: older-than
James E. Blaird134c6d2017-07-26 16:09:34 -0700247
248 If present, the approval must be older than this amount of time
249 to match. Provide a time interval as a number with a suffix of
250 "w" (weeks), "d" (days), "h" (hours), "m" (minutes), "s"
251 (seconds). Example ``48h`` or ``2d``.
252
James E. Blair94375912017-07-28 17:20:27 -0700253 .. attr:: newer-than
James E. Blaird134c6d2017-07-26 16:09:34 -0700254
255 If present, the approval must be newer than this amount
256 of time to match. Same format as "older-than".
257
258 Any other field is interpreted as a review category and value
259 pair. For example ``Verified: 1`` would require that the
260 approval be for a +1 vote in the "Verified" column. The value
261 may either be a single value or a list: ``Verified: [1, 2]``
262 would match either a +1 or +2 vote.
263
James E. Blair94375912017-07-28 17:20:27 -0700264 .. attr:: open
James E. Blaird134c6d2017-07-26 16:09:34 -0700265
266 A boolean value (``true`` or ``false``) that indicates whether
267 the change must be open or closed in order to be enqueued.
268
James E. Blair94375912017-07-28 17:20:27 -0700269 .. attr:: current-patchset
James E. Blaird134c6d2017-07-26 16:09:34 -0700270
271 A boolean value (``true`` or ``false``) that indicates whether the
272 change must be the current patchset in order to be enqueued.
273
James E. Blair94375912017-07-28 17:20:27 -0700274 .. attr:: status
James E. Blaird134c6d2017-07-26 16:09:34 -0700275
276 A string value that corresponds with the status of the change
277 reported by the trigger.
278
James E. Blair94375912017-07-28 17:20:27 -0700279.. attr:: pipeline.reject.<gerrit source>
James E. Blaird134c6d2017-07-26 16:09:34 -0700280
281 The `reject` attribute is the mirror of the `require` attribute. It
282 also accepts a dictionary under the connection name. This
283 dictionary supports the following attributes:
284
James E. Blair94375912017-07-28 17:20:27 -0700285 .. attr:: approval
James E. Blaird134c6d2017-07-26 16:09:34 -0700286
287 This takes a list of approvals. If an approval matches the
288 provided criteria the change can not be entered into the
James E. Blair91fe4832017-07-28 17:28:26 -0700289 pipeline. It follows the same syntax as
290 :attr:`pipeline.require.<gerrit source>.approval`.
James E. Blaird134c6d2017-07-26 16:09:34 -0700291
James E. Blaird23f45d2017-08-03 16:37:13 -0700292 Example to reject a change with any negative vote:
James E. Blaird134c6d2017-07-26 16:09:34 -0700293
James E. Blaird23f45d2017-08-03 16:37:13 -0700294 .. code-block:: yaml
295
296 reject:
297 my-gerrit:
298 approval:
299 - Code-Review: [-1, -2]