blob: 795df723dd0e12a7bfec6adeda27600f68b4c28f [file] [log] [blame]
James E. Blaircdd00072012-06-08 19:17:28 -07001:title: Project Gating
2
James E. Blaireff5a9d2017-06-20 00:00:37 -07003.. _project_gating:
4
James E. Blaircdd00072012-06-08 19:17:28 -07005Project Gating
6==============
7
8Traditionally, many software development projects merge changes from
9developers into the repository, and then identify regressions
10resulting from those changes (perhaps by running a test suite with a
James E. Blaireff5a9d2017-06-20 00:00:37 -070011continuous integration system), followed by more patches to fix those
12bugs. When the mainline of development is broken, it can be very
13frustrating for developers and can cause lost productivity,
14particularly so when the number of contributors or contributions is
15large.
James E. Blaircdd00072012-06-08 19:17:28 -070016
17The process of gating attempts to prevent changes that introduce
18regressions from being merged. This keeps the mainline of development
19open and working for all developers, and only when a change is
20confirmed to work without disruption is it merged.
21
22Many projects practice an informal method of gating where developers
23with mainline commit access ensure that a test suite runs before
24merging a change. With more developers, more changes, and more
25comprehensive test suites, that process does not scale very well, and
26is not the best use of a developer's time. Zuul can help automate
27this process, with a particular emphasis on ensuring large numbers of
28changes are tested correctly.
29
Antoine Musso55867532014-01-10 18:24:35 +010030Testing in parallel
31-------------------
32
James E. Blaircdd00072012-06-08 19:17:28 -070033A particular focus of Zuul is ensuring correctly ordered testing of
34changes in parallel. A gating system should always test each change
35applied to the tip of the branch exactly as it is going to be merged.
36A simple way to do that would be to test one change at a time, and
37merge it only if it passes tests. That works very well, but if
38changes take a long time to test, developers may have to wait a long
39time for their changes to make it into the repository. With some
40projects, it may take hours to test changes, and it is easy for
41developers to create changes at a rate faster than they can be tested
42and merged.
43
James E. Blair91fe4832017-07-28 17:28:26 -070044Zuul's :value:`dependent pipeline manager<pipeline.manager.dependent>`
James E. Blaireff5a9d2017-06-20 00:00:37 -070045allows for parallel execution of test jobs for gating while ensuring
46changes are tested correctly, exactly as if they had been tested one
47at a time. It does this by performing speculative execution of test
48jobs; it assumes that all jobs will succeed and tests them in parallel
49accordingly. If they do succeed, they can all be merged. However, if
50one fails, then changes that were expecting it to succeed are
51re-tested without the failed change. In the best case, as many
52changes as execution contexts are available may be tested in parallel
53and merged at once. In the worst case, changes are tested one at a
54time (as each subsequent change fails, changes behind it start again).
James E. Blaircdd00072012-06-08 19:17:28 -070055
56For example, if a core developer approves five changes in rapid
57succession::
58
59 A, B, C, D, E
60
61Zuul queues those changes in the order they were approved, and notes
Antoine Musso3a43e142013-10-30 23:51:58 +010062that each subsequent change depends on the one ahead of it merging:
James E. Blaircdd00072012-06-08 19:17:28 -070063
Antoine Musso3a43e142013-10-30 23:51:58 +010064.. blockdiag::
65
66 blockdiag foo {
67 node_width = 40;
68 span_width = 40;
69 A <- B <- C <- D <- E;
70 }
James E. Blaircdd00072012-06-08 19:17:28 -070071
72Zuul then starts immediately testing all of the changes in parallel.
73But in the case of changes that depend on others, it instructs the
74test system to include the changes ahead of it, with the assumption
75they pass. That means jobs testing change *B* include change *A* as
76well::
77
78 Jobs for A: merge change A, then test
79 Jobs for B: merge changes A and B, then test
80 Jobs for C: merge changes A, B and C, then test
81 Jobs for D: merge changes A, B, C and D, then test
82 Jobs for E: merge changes A, B, C, D and E, then test
83
Antoine Musso3a43e142013-10-30 23:51:58 +010084Hence jobs triggered to tests A will only test A and ignore B, C, D:
James E. Blaircdd00072012-06-08 19:17:28 -070085
Antoine Musso3a43e142013-10-30 23:51:58 +010086.. blockdiag::
James E. Blaircdd00072012-06-08 19:17:28 -070087
Antoine Musso3a43e142013-10-30 23:51:58 +010088 blockdiag foo {
89 node_width = 40;
90 span_width = 40;
91 master -> A -> B -> C -> D -> E;
92 group jobs_for_A {
93 label = "Merged changes for A";
94 master -> A;
95 }
96 group ignored_to_test_A {
97 label = "Ignored changes";
98 color = "lightgray";
99 B -> C -> D -> E;
100 }
101 }
James E. Blaircdd00072012-06-08 19:17:28 -0700102
Antoine Musso3a43e142013-10-30 23:51:58 +0100103The jobs for E would include the whole dependency chain: A, B, C, D, and E.
104E will be tested assuming A, B, C, and D passed:
105
106.. blockdiag::
107
108 blockdiag foo {
109 node_width = 40;
110 span_width = 40;
111 group jobs_for_E {
112 label = "Merged changes for E";
113 master -> A -> B -> C -> D -> E;
114 }
115 }
116
117If changes *A* and *B* pass tests (green), and *C*, *D*, and *E* fail (red):
118
119.. blockdiag::
120
121 blockdiag foo {
122 node_width = 40;
123 span_width = 40;
124
125 A [color = lightgreen];
126 B [color = lightgreen];
127 C [color = pink];
128 D [color = pink];
129 E [color = pink];
130
131 master <- A <- B <- C <- D <- E;
132 }
133
134Zuul will merge change *A* followed by change *B*, leaving this queue:
135
136.. blockdiag::
137
138 blockdiag foo {
139 node_width = 40;
140 span_width = 40;
141
142 C [color = pink];
143 D [color = pink];
144 E [color = pink];
145
146 C <- D <- E;
147 }
James E. Blaircdd00072012-06-08 19:17:28 -0700148
149Since *D* was dependent on *C*, it is not clear whether *D*'s failure is the
Antoine Musso3a43e142013-10-30 23:51:58 +0100150result of a defect in *D* or *C*:
James E. Blaircdd00072012-06-08 19:17:28 -0700151
Antoine Musso3a43e142013-10-30 23:51:58 +0100152.. blockdiag::
James E. Blaircdd00072012-06-08 19:17:28 -0700153
Antoine Musso3a43e142013-10-30 23:51:58 +0100154 blockdiag foo {
155 node_width = 40;
156 span_width = 40;
James E. Blaircdd00072012-06-08 19:17:28 -0700157
Antoine Musso3a43e142013-10-30 23:51:58 +0100158 C [color = pink];
159 D [label = "D\n?"];
160 E [label = "E\n?"];
161
162 C <- D <- E;
163 }
164
165Since *C* failed, Zuul will report its failure and drop *C* from the queue,
166keeping D and E:
167
168.. blockdiag::
169
170 blockdiag foo {
171 node_width = 40;
172 span_width = 40;
173
174 D [label = "D\n?"];
175 E [label = "E\n?"];
176
177 D <- E;
178 }
James E. Blaircdd00072012-06-08 19:17:28 -0700179
180This queue is the same as if two new changes had just arrived, so Zuul
181starts the process again testing *D* against the tip of the branch, and
Antoine Musso3a43e142013-10-30 23:51:58 +0100182*E* against *D*:
183
184.. blockdiag::
185
186 blockdiag foo {
187 node_width = 40;
188 span_width = 40;
189 master -> D -> E;
190 group jobs_for_D {
191 label = "Merged changes for D";
192 master -> D;
193 }
194 group ignored_to_test_D {
195 label = "Skip";
196 color = "lightgray";
197 E;
198 }
199 }
200
201.. blockdiag::
202
203 blockdiag foo {
204 node_width = 40;
205 span_width = 40;
206 group jobs_for_E {
207 label = "Merged changes for E";
208 master -> D -> E;
209 }
210 }
211
Antoine Musso55867532014-01-10 18:24:35 +0100212
James E. Blair096a80a2015-09-28 14:19:31 -0700213Cross Project Testing
214---------------------
Antoine Musso55867532014-01-10 18:24:35 +0100215
216When your projects are closely coupled together, you want to make sure
217changes entering the gate are going to be tested with the version of
218other projects currently enqueued in the gate (since they will
219eventually be merged and might introduce breaking features).
220
James E. Blaireff5a9d2017-06-20 00:00:37 -0700221Such relationships can be defined in Zuul configuration by placing
222projects in a shared queue within a dependent pipeline. Whenever
223changes for any project enter a pipeline with such a shared queue,
224they are tested together, such that the commits for the changes ahead
225in the queue are automatically present in the jobs for the changes
226behind them. See :ref:`project` for more details.
Antoine Musso55867532014-01-10 18:24:35 +0100227
James E. Blaireff5a9d2017-06-20 00:00:37 -0700228A given dependent pipeline may have as many shared change queues as
229necessary, so groups of related projects may share a change queue
David Shrewsburyb040b0a2017-08-03 15:53:59 -0400230without interfering with unrelated projects.
231:value:`Independent pipelines <pipeline.manager.independent>` do
James E. Blaireff5a9d2017-06-20 00:00:37 -0700232not use shared change queues, however, they may still be used to test
233changes across projects using cross-project dependencies.
Antoine Musso55867532014-01-10 18:24:35 +0100234
James E. Blaireff5a9d2017-06-20 00:00:37 -0700235.. _dependencies:
Antoine Musso55867532014-01-10 18:24:35 +0100236
James E. Blaireff5a9d2017-06-20 00:00:37 -0700237Cross-Project Dependencies
238--------------------------
Antoine Musso55867532014-01-10 18:24:35 +0100239
James E. Blaireff5a9d2017-06-20 00:00:37 -0700240Zuul permits users to specify dependencies across projects. Using a
241special footer in Git commit messages, users may specify that a change
242depends on another change in any repository known to Zuul.
Antoine Musso55867532014-01-10 18:24:35 +0100243
James E. Blaireff5a9d2017-06-20 00:00:37 -0700244Zuul's cross-project dependencies behave like a directed acyclic graph
245(DAG), like git itself, to indicate a one-way dependency relationship
246between changes in different git repositories. Change A may depend on
247B, but B may not depend on A.
Antoine Musso55867532014-01-10 18:24:35 +0100248
James E. Blaireff5a9d2017-06-20 00:00:37 -0700249.. TODO: update for v3 crd syntax
James E. Blair096a80a2015-09-28 14:19:31 -0700250
Antoine Musso281a89e2015-09-30 15:05:49 +0200251To use them, include ``Depends-On: <gerrit-change-id>`` in the footer of
James E. Blair096a80a2015-09-28 14:19:31 -0700252a commit message. Use the full Change-ID ('I' + 40 characters).
253
254
Antoine Musso281a89e2015-09-30 15:05:49 +0200255Dependent Pipeline
256~~~~~~~~~~~~~~~~~~
James E. Blair096a80a2015-09-28 14:19:31 -0700257
James E. Blaireff5a9d2017-06-20 00:00:37 -0700258When Zuul sees changes with cross-project dependencies, it serializes
259them in the usual manner when enqueuing them into a pipeline. This
260means that if change A depends on B, then when they are added to a
261dependent pipeline, B will appear first and A will follow:
James E. Blair096a80a2015-09-28 14:19:31 -0700262
Antoine Musso281a89e2015-09-30 15:05:49 +0200263.. blockdiag::
264 :align: center
James E. Blair096a80a2015-09-28 14:19:31 -0700265
Antoine Musso281a89e2015-09-30 15:05:49 +0200266 blockdiag crd {
267 orientation = portrait
268 span_width = 30
269 class greendot [
270 label = "",
271 shape = circle,
272 color = green,
273 width = 20, height = 20
274 ]
James E. Blair096a80a2015-09-28 14:19:31 -0700275
Antoine Musso281a89e2015-09-30 15:05:49 +0200276 A_status [ class = greendot ]
277 B_status [ class = greendot ]
278 B_status -- A_status
279
280 'Change B\nChange-Id: Iabc' <- 'Change A\nDepends-On: Iabc'
281 }
282
283If tests for B fail, both B and A will be removed from the pipeline, and
284it will not be possible for A to merge until B does.
285
286
287.. note::
288
James E. Blaireff5a9d2017-06-20 00:00:37 -0700289 If changes with cross-project dependencies do not share a change
290 queue then Zuul is unable to enqueue them together, and the first
291 will be required to merge before the second is enqueued.
Antoine Musso281a89e2015-09-30 15:05:49 +0200292
293Independent Pipeline
294~~~~~~~~~~~~~~~~~~~~
295
296When changes are enqueued into an independent pipeline, all of the
James E. Blaireff5a9d2017-06-20 00:00:37 -0700297related dependencies (both normal git-dependencies that come from
298parent commits as well as cross-project dependencies) appear in a
299dependency graph, as in a dependent pipeline. This means that even in
300an independent pipeline, your change will be tested with its
301dependencies. Changes that were previously unable to be fully tested
302until a related change landed in a different repository may now be
303tested together from the start.
James E. Blair096a80a2015-09-28 14:19:31 -0700304
James E. Blaireff5a9d2017-06-20 00:00:37 -0700305All of the changes are still independent (you will note that the whole
306pipeline does not share a graph as in a dependent pipeline), but for
307each change tested, all of its dependencies are visually connected to
308it, and they are used to construct the git repositories that Zuul uses
Antoine Musso281a89e2015-09-30 15:05:49 +0200309when testing.
310
James E. Blair096a80a2015-09-28 14:19:31 -0700311When looking at this graph on the status page, you will note that the
312dependencies show up as grey dots, while the actual change tested shows
Antoine Musso281a89e2015-09-30 15:05:49 +0200313up as red or green (depending on the jobs results):
314
315.. blockdiag::
316 :align: center
317
318 blockdiag crdgrey {
319 orientation = portrait
320 span_width = 30
321 class dot [
322 label = "",
323 shape = circle,
324 width = 20, height = 20
325 ]
326
327 A_status [class = "dot", color = green]
328 B_status [class = "dot", color = grey]
329 B_status -- A_status
330
331 "Change B" <- "Change A\nDepends-On: B"
332 }
333
334This is to indicate that the grey changes are only there to establish
335dependencies. Even if one of the dependencies is also being tested, it
336will show up as a grey dot when used as a dependency, but separately and
337additionally will appear as its own red or green dot for its test.
338
James E. Blair096a80a2015-09-28 14:19:31 -0700339
James E. Blaireff5a9d2017-06-20 00:00:37 -0700340.. TODO: relevant for v3?
341
James E. Blair096a80a2015-09-28 14:19:31 -0700342Multiple Changes
343~~~~~~~~~~~~~~~~
344
345A Gerrit change ID may refer to multiple changes (on multiple branches
346of the same project, or even multiple projects). In these cases, Zuul
347will treat all of the changes with that change ID as dependencies. So
348if you say that change in project A Depends-On a change ID that has
349changes in two branches of project B, then when testing the change to
350project A, both project B changes will be applied, and when deciding
351whether the project A change can merge, both changes must merge ahead
352of it.
353
Antoine Musso281a89e2015-09-30 15:05:49 +0200354.. blockdiag::
355 :align: center
356
357 blockdiag crdmultirepos {
358 orientation = portrait
359 span_width = 30
360 class greendot [
361 label = "",
362 shape = circle,
363 color = green,
364 width = 20, height = 20
365 ]
366
367 B_stable_status [ class = "greendot" ]
368 B_master_status [ class = "greendot" ]
369 A_status [ class = "greendot" ]
370 B_stable_status -- B_master_status -- A_status
371
372 A [ label = "Repo A\nDepends-On: I123" ]
373 group {
374 orientation = portrait
375 label = "Dependencies"
376 color = "lightgray"
377
378 B_stable [ label = "Repo B\nChange-Id: I123\nBranch: stable" ]
379 B_master [ label = "Repo B\nChange-Id: I123\nBranch: master" ]
380 }
381 B_master <- A
382 B_stable <- A
383
384 }
385
James E. Blair096a80a2015-09-28 14:19:31 -0700386A change may depend on more than one Gerrit change ID as well. So it
387is possible for a change in project A to depend on a change in project
Antoine Musso281a89e2015-09-30 15:05:49 +0200388B and a change in project C. Simply add more ``Depends-On:`` lines to
389the commit message footer.
390
391.. blockdiag::
392 :align: center
393
394 blockdiag crdmultichanges {
395 orientation = portrait
396 span_width = 30
397 class greendot [
398 label = "",
399 shape = circle,
400 color = green,
401 width = 20, height = 20
402 ]
403
404 C_status [ class = "greendot" ]
405 B_status [ class = "greendot" ]
406 A_status [ class = "greendot" ]
407 C_status -- B_status -- A_status
408
409 A [ label = "Repo A\nDepends-On: I123\nDepends-On: Iabc" ]
410 group {
411 orientation = portrait
412 label = "Dependencies"
413 color = "lightgray"
414
415 B [ label = "Repo B\nChange-Id: I123" ]
416 C [ label = "Repo C\nChange-Id: Iabc" ]
417 }
418 B, C <- A
419 }
James E. Blair096a80a2015-09-28 14:19:31 -0700420
James E. Blaireff5a9d2017-06-20 00:00:37 -0700421.. TODO: update for v3
422
James E. Blair096a80a2015-09-28 14:19:31 -0700423Cycles
424~~~~~~
425
James E. Blaireff5a9d2017-06-20 00:00:37 -0700426If a cycle is created by use of cross-project dependencies, Zuul will
427abort its work very early. There will be no message in Gerrit and no
428changes that are part of the cycle will be enqueued into any pipeline.
429This is to protect Zuul from infinite loops.