pipelines.md 10,2 КБ
Newer Older
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
1
# Introduction to pipelines and jobs
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
2

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
3
> Introduced in GitLab 8.8.
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
4

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
5
6
7
8
9
NOTE: **Note:**
If you have a [mirrored repository where GitLab pulls from](https://docs.gitlab.com/ee/workflow/repository_mirroring.html#pulling-from-a-remote-repository),
you may need to enable pipeline triggering in your project's
**Settings > Repository > Pull from a remote repository > Trigger pipelines for mirror updates**.

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
10
11
## Pipelines

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
12
13
A pipeline is a group of [jobs][] that get executed in [stages][](batches).
All of the jobs in a stage are executed in parallel (if there are enough
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
14
concurrent [Runners]), and if they all succeed, the pipeline moves on to the
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
15
next stage. If one of the jobs fails, the next stage is not (usually)
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
16
17
18
19
20
21
22
executed. You can access the pipelines page in your project's **Pipelines** tab.

In the following image you can see that the pipeline consists of four stages
(`build`, `test`, `staging`, `production`) each one having one or more jobs.

>**Note:**
GitLab capitalizes the stages' names when shown in the [pipeline graphs](#pipeline-graphs).
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
23

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
24
25
![Pipelines example](img/pipelines.png)

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
26
## Types of pipelines
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
27
28
29

There are three types of pipelines that often use the single shorthand of "pipeline". People often talk about them as if each one is "the" pipeline, but really, they're just pieces of a single, comprehensive pipeline.

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
30
![Types of Pipelines](img/types-of-pipelines.svg)
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
31
32
33

1. **CI Pipeline**: Build and test stages defined in `.gitlab-ci.yml`
2. **Deploy Pipeline**: Deploy stage(s) defined in `.gitlab-ci.yml` The flow of deploying code to servers through various stages: e.g. development to staging to production
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
34
3. **Project Pipeline**: Cross-project CI dependencies [triggered via API][triggers], particularly for micro-services, but also for complicated build dependencies: e.g. api -> front-end, ce/ee -> omnibus.
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
35

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
36
## Development workflows
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
37
38
39
40
41
42
43

Pipelines accommodate several development workflows:

1. **Branch Flow** (e.g. different branch for dev, qa, staging, production)
2. **Trunk-based Flow** (e.g. feature branches and single master branch, possibly with tags for releases)
3. **Fork-based Flow** (e.g. merge requests come from forks)

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
44
Example continuous delivery flow:
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
45

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
46
![CD Flow](img/pipelines-goal.svg)
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
47

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
48
## Jobs
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
49

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
50
51
Jobs can be defined in the [`.gitlab-ci.yml`][jobs-yaml] file. Not to be
confused with a `build` job or `build` stage.
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
52
53
54
55
56
57

## Defining pipelines

Pipelines are defined in `.gitlab-ci.yml` by specifying [jobs] that run in
[stages].

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
58
See the reference [documentation for jobs](yaml/README.md#jobs).
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
59
60
61

## Seeing pipeline status

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
62
63
64
65
66
You can find the current and historical pipeline runs under your project's
**Pipelines** tab. Clicking on a pipeline will show the jobs that were run for
that pipeline.

![Pipelines index page](img/pipelines_index.png)
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
67

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
68
## Seeing job status
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
69

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
70
When you visit a single pipeline you can see the related jobs for that pipeline.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
71
Clicking on an individual job will show you its job trace, and allow you to
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
72
73
74
75
cancel the job, retry it, or erase the job trace.

![Pipelines example](img/pipelines.png)

Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
76
77
## Seeing the failure reason for jobs

Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
78
> [Introduced][ce-17782] in GitLab 10.7.
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
79
80
81
82
83
84
85
86
87
88
89
90

When a pipeline fails or is allowed to fail, there are several places where you
can quickly check the reason it failed:

- **In the pipeline graph** present on the pipeline detail view.
- **In the pipeline widgets** present in the merge requests and commit pages.
- **In the job views** present in the global and detailed views of a job.

In any case, if you hover over the failed job you can see the reason it failed.

![Pipeline detail](img/job_failure_reason.png)

Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
91
92
From [GitLab 10.8][ce-17814] you can also see the reason it failed on the Job detail page.

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
## Pipeline graphs

> [Introduced][ce-5742] in GitLab 8.11.

Pipelines can be complex structures with many sequential and parallel jobs.
To make it a little easier to see what is going on, you can view a graph
of a single pipeline and its status.

A pipeline graph can be shown in two different ways depending on what page you
are on.

---

The regular pipeline graph that shows the names of the jobs of each stage can
be found when you are on a [single pipeline page](#seeing-pipeline-status).

![Pipelines example](img/pipelines.png)

Then, there is the pipeline mini graph which takes less space and can give you a
quick glance if all jobs pass or something failed. The pipeline mini graph can
be found when you visit:

- the pipelines index page
- a single commit page
- a merge request page

That way, you can see all related jobs for a single commit and the net result
of each stage of your pipeline. This allows you to quickly see what failed and
fix it. Stages in pipeline mini graphs are collapsible. Hover your mouse over
them and click to expand their jobs.

| **Mini graph** | **Mini graph expanded** |
| :------------: | :---------------------: |
| ![Pipelines mini graph](img/pipelines_mini_graph_simple.png) | ![Pipelines mini graph extended](img/pipelines_mini_graph.png) |

### Grouping similar jobs in the pipeline graph

> [Introduced][ce-6242] in GitLab 8.12.

If you have many similar jobs, your pipeline graph becomes very long and hard
to read. For that reason, similar jobs can automatically be grouped together.
If the job names are formatted in certain ways, they will be collapsed into
a single group in regular pipeline graphs (not the mini graphs).
You'll know when a pipeline has grouped jobs if you don't see the retry or
cancel button inside them. Hovering over them will show the number of grouped
jobs. Click to expand them.

![Grouped pipelines](img/pipelines_grouped.png)

The basic requirements is that there are two numbers separated with one of
the following (you can even use them interchangeably):

- a space
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
146
- a slash (`/`)
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
- a colon (`:`)

>**Note:**
More specifically, [it uses][regexp] this regular expression: `\d+[\s:\/\\]+\d+\s*`.

The jobs will be ordered by comparing those two numbers from left to right. You
usually want the first to be the index and the second the total.

For example, the following jobs will be grouped under a job named `test`:

- `test 0 3` => `test`
- `test 1 3` => `test`
- `test 2 3` => `test`

The following jobs will be grouped under a job named `test ruby`:

- `test 1:2 ruby` => `test ruby`
- `test 2:2 ruby` => `test ruby`

The following jobs will be grouped under a job named `test ruby` as well:

- `1/3 test ruby` => `test ruby`
- `2/3 test ruby` => `test ruby`
- `3/3 test ruby` => `test ruby`

### Manual actions from the pipeline graph

> [Introduced][ce-7931] in GitLab 8.15.

[Manual actions][manual] allow you to require manual interaction before moving
forward with a particular job in CI. Your entire pipeline can run automatically,
but the actual [deploy to production][env-manual] will require a click.

You can do this straight from the pipeline graph. Just click on the play button
to execute that particular job. For example, in the image below, the `production`
stage has a job with a manual action.

![Pipelines example](img/pipelines.png)
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
185

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
### Ordering of jobs in pipeline graphs

**Regular pipeline graph**

In the single pipeline page, jobs are sorted by name.

**Mini pipeline graph**

> [Introduced][ce-9760] in GitLab 9.0.

In the pipeline mini graphs, the jobs are sorted first by severity and then
by name. The order of severity is:

- failed
- warning
- pending
- running
- manual
- canceled
- success
- skipped
- created

![Pipeline mini graph sorting](img/pipelines_mini_graph_sorting.png)

Lin Jen-Shin's avatar
Lin Jen-Shin включено в состав коммита
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
## How the pipeline duration is calculated

Total running time for a given pipeline would exclude retries and pending
(queue) time. We could reduce this problem down to finding the union of
periods.

So each job would be represented as a `Period`, which consists of
`Period#first` as when the job started and `Period#last` as when the
job was finished. A simple example here would be:

* A (1, 3)
* B (2, 4)
* C (6, 7)

Here A begins from 1, and ends to 3. B begins from 2, and ends to 4.
C begins from 6, and ends to 7. Visually it could be viewed as:

```
0  1  2  3  4  5  6  7
   AAAAAAA
      BBBBBBB
                  CCCC
```

The union of A, B, and C would be (1, 4) and (6, 7), therefore the
total running time should be:

```
(4 - 1) + (7 - 6) => 4
```

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
242
243
## Badges

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
244
Pipeline status and test coverage report badges are available. You can find their
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
245
respective link in the [Pipelines settings] page.
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
246

Fabio Busatto's avatar
Fabio Busatto включено в состав коммита
247
248
249
250
251
252
253
254
255
256
257
258
259
260
## Security on protected branches

A strict security model is enforced when pipelines are executed on
[protected branches](../user/project/protected_branches.md).

The following actions are allowed on protected branches only if the user is
[allowed to merge or push](../user/project/protected_branches.md#using-the-allowed-to-merge-and-allowed-to-push-settings)
on that specific branch:
- run **manual pipelines** (using Web UI or Pipelines API)
- run **scheduled pipelines**
- run pipelines using **triggers**
- trigger **manual actions** on existing pipelines
- **retry/cancel** existing jobs (using Web UI or Pipelines API)

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
261
**Variables** marked as **protected** are accessible only to jobs that
Fabio Busatto's avatar
Fabio Busatto включено в состав коммита
262
263
264
265
266
267
268
269
270
run on protected branches, avoiding untrusted users to get unintended access to
sensitive information like deployment credentials and tokens.

**Runners** marked as **protected** can run jobs only on protected
branches, avoiding untrusted code to be executed on the protected runner and
preserving deployment keys and other credentials from being unintentionally
accessed. In order to ensure that jobs intended to be executed on protected
runners will not use regular runners, they must be tagged accordingly.

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
271
272
[jobs]: #jobs
[jobs-yaml]: yaml/README.md#jobs
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
273
274
[manual]: yaml/README.md#manual
[env-manual]: environments.md#manually-deploying-to-environments
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
275
[stages]: yaml/README.md#stages
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
276
[runners]: runners/README.html
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
277
[pipelines settings]: ../user/project/pipelines/settings.md
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
278
[triggers]: triggers/README.md
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
279
280
281
[ce-5742]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5742
[ce-6242]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6242
[ce-7931]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7931
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
282
[ce-9760]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9760
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
283
[ce-17782]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/17782
Mayra Cabrera's avatar
Mayra Cabrera включено в состав коммита
284
[ce-17814]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/17814
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
285
[regexp]: https://gitlab.com/gitlab-org/gitlab-ce/blob/2f3dc314f42dbd79813e6251792853bc231e69dd/app/models/commit_status.rb#L99