README.md 26,6 КБ
Newer Older
Douwe Maan's avatar
Douwe Maan включено в состав коммита
1
2
# Configuration of your builds with .gitlab-ci.yml

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
3
4
5
6
7
8
9
10
11
12
13
14
15
This document describes the usage of `.gitlab-ci.yml`, the file that is used by
GitLab Runner to manage your project's builds.

If you want a quick introduction to GitLab CI, follow our
[quick start guide](../quick_start/README.md).

---

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [.gitlab-ci.yml](#gitlab-ci-yml)
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
16
17
18
19
20
21
22
23
  - [image and services](#image-and-services)
  - [before_script](#before_script)
  - [after_script](#after_script)
  - [stages](#stages)
  - [types](#types)
  - [variables](#variables)
  - [cache](#cache)
    - [cache:key](#cache-key)
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
24
- [Jobs](#jobs)
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
25
26
27
28
29
30
31
32
33
34
35
36
37
  - [script](#script)
  - [stage](#stage)
  - [only and except](#only-and-except)
  - [job variables](#job-variables)
  - [tags](#tags)
  - [when](#when)
  - [environment](#environment)
  - [artifacts](#artifacts)
    - [artifacts:name](#artifactsname)
    - [artifacts:when](#artifactswhen)
    - [artifacts:expire_in](#artifactsexpire_in)
  - [dependencies](#dependencies)
  - [before_script and after_script](#before_script-and-after_script)
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
38
39
- [Git Strategy](#git-strategy)
- [Shallow cloning](#shallow-cloning)
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
40
41
- [Hidden jobs](#hidden-jobs)
- [Special YAML features](#special-yaml-features)
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
42
43
  - [Anchors](#anchors)
- [Validate the .gitlab-ci.yml](#validate-the-gitlab-ciyml)
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
44
45
46
47
48
49
50
51
52
- [Skipping builds](#skipping-builds)
- [Examples](#examples)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

---

## .gitlab-ci.yml

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
53
54
55
56
57
58
From version 7.12, GitLab CI uses a [YAML](https://en.wikipedia.org/wiki/YAML)
file (`.gitlab-ci.yml`) for the project configuration. It is placed in the root
of your repository and contains definitions of how your project should be built.

The YAML file defines a set of jobs with constraints stating when they should
be run. The jobs are defined as top-level elements with a name and always have
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
59
to contain at least the `script` clause:
Douwe Maan's avatar
Douwe Maan включено в состав коммита
60
61
62
63
64
65
66
67
68

```yaml
job1:
  script: "execute-script-for-job1"

job2:
  script: "execute-script-for-job2"
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
69
70
71
72
73
The above example is the simplest possible CI configuration with two separate
jobs, where each of the jobs executes a different command.

Of course a command can execute code directly (`./configure;make;make install`)
or run a script (`test.sh`) in the repository.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
74

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
75
Jobs are used to create builds, which are then picked up by
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
76
77
[Runners](../runners/README.md) and executed within the environment of the
Runner. What is important, is that each job is run independently from each
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
78
other.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
79

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
80
81
The YAML syntax allows for using more complex job specifications than in the
above example:
Douwe Maan's avatar
Douwe Maan включено в состав коммита
82
83

```yaml
James Lopez's avatar
James Lopez включено в состав коммита
84
image: ruby:2.1
Douwe Maan's avatar
Douwe Maan включено в состав коммита
85
86
87
88
services:
  - postgres

before_script:
frodsan's avatar
frodsan включено в состав коммита
89
  - bundle install
Douwe Maan's avatar
Douwe Maan включено в состав коммита
90

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
91
92
93
after_script:
  - rm secrets

Douwe Maan's avatar
Douwe Maan включено в состав коммита
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
stages:
  - build
  - test
  - deploy

job1:
  stage: build
  script:
    - execute-script-for-job1
  only:
    - master
  tags:
    - docker
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
109
There are a few reserved `keywords` that **cannot** be used as job names:
Douwe Maan's avatar
Douwe Maan включено в состав коммита
110

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
111
| Keyword       | Required | Description |
Douwe Maan's avatar
Douwe Maan включено в состав коммита
112
|---------------|----------|-------------|
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
113
114
115
116
117
| image         | no | Use docker image, covered in [Use Docker](../docker/README.md) |
| services      | no | Use docker services, covered in [Use Docker](../docker/README.md) |
| stages        | no | Define build stages |
| types         | no | Alias for `stages` |
| before_script | no | Define commands that run before each job's script |
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
118
| after_script  | no | Define commands that run after each job's script |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
119
120
| variables     | no | Define build variables |
| cache         | no | Define list of files that should be cached between subsequent runs |
Douwe Maan's avatar
Douwe Maan включено в состав коммита
121
122

### image and services
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
123
124
125

This allows to specify a custom Docker image and a list of services that can be
used for time of the build. The configuration of this feature is covered in
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
126
[a separate document](../docker/README.md).
Douwe Maan's avatar
Douwe Maan включено в состав коммита
127
128

### before_script
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
129
130
131

`before_script` is used to define the command that should be run before all
builds, including deploy builds. This can be an array or a multi-line string.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
132

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
133
134
### after_script

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
135
>**Note:**
Max Raab's avatar
Max Raab включено в состав коммита
136
Introduced in GitLab 8.7 and requires Gitlab Runner v1.2
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
137

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
138
139
140
`after_script` is used to define the command that will be run after for all
builds. This has to be an array or a multi-line string.

Douwe Maan's avatar
Douwe Maan включено в состав коммита
141
### stages
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
142

Douwe Maan's avatar
Douwe Maan включено в состав коммита
143
144
145
146
147
148
`stages` is used to define build stages that can be used by jobs.
The specification of `stages` allows for having flexible multi stage pipelines.

The ordering of elements in `stages` defines the ordering of builds' execution:

1. Builds of the same stage are run in parallel.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
149
150
1. Builds of the next stage are run after the jobs from the previous stage
   complete successfully.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
151
152

Let's consider the following example, which defines 3 stages:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
153
154

```yaml
Douwe Maan's avatar
Douwe Maan включено в состав коммита
155
156
157
158
159
160
161
stages:
  - build
  - test
  - deploy
```

1. First all jobs of `build` are executed in parallel.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
162
163
164
1. If all jobs of `build` succeed, the `test` jobs are executed in parallel.
1. If all jobs of `test` succeed, the `deploy` jobs are executed in parallel.
1. If all jobs of `deploy` succeed, the commit is marked as `success`.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
165
166
1. If any of the previous jobs fails, the commit is marked as `failed` and no
   jobs of further stage are executed.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
167
168
169

There are also two edge cases worth mentioning:

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
170
1. If no `stages` are defined in `.gitlab-ci.yml`, then by default the `build`,
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
171
   `test` and `deploy` are allowed to be used as job's stage by default.
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
172
2. If a job doesn't specify a `stage`, the job is assigned the `test` stage.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
173
174

### types
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
175

Douwe Maan's avatar
Douwe Maan включено в состав коммита
176
177
178
179
Alias for [stages](#stages).

### variables

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
180
181
>**Note:**
Introduced in GitLab Runner v0.5.0.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
182

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
183
184
185
GitLab CI allows you to add variables to `.gitlab-ci.yml` that are set in the
build environment. The variables are stored in the git repository and are meant
to store non-sensitive project configuration, for example:
Douwe Maan's avatar
Douwe Maan включено в состав коммита
186
187
188
189
190
191
192
193

```yaml
variables:
  DATABASE_URL: "postgres://postgres@postgres/my_database"
```

These variables can be later used in all executed commands and scripts.

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
194
195
The YAML-defined variables are also set to all created service containers,
thus allowing to fine tune them.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
196

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
197
198
Variables can be also defined on [job level](#job-variables).

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
199
200
### cache

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
201
202
203
>**Note:**
Introduced in GitLab Runner v0.7.0.

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
204
`cache` is used to specify a list of files and directories which should be
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
205
206
207
cached between builds.

**By default the caching is enabled per-job and per-branch.**
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
208
209
210

If `cache` is defined outside the scope of the jobs, it means it is set
globally and all jobs will use its definition.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
211

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
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
242
243
244
Cache all files in `binaries` and `.config`:

```yaml
rspec:
  script: test
  cache:
    paths:
    - binaries/
    - .config
```

Cache all Git untracked files:

```yaml
rspec:
  script: test
  cache:
    untracked: true
```

Cache all Git untracked files and files in `binaries`:

```yaml
rspec:
  script: test
  cache:
    untracked: true
    paths:
    - binaries/
```

Locally defined cache overwrites globally defined options. This will cache only
`binaries/`:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
245
246

```yaml
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
247
248
cache:
  paths:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
249
250
251
252
253
254
255
  - my/files

rspec:
  script: test
  cache:
    paths:
    - binaries/
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
256
257
```

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
258
259
The cache is provided on a best-effort basis, so don't expect that the cache
will be always present. For implementation details, please check GitLab Runner.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
260

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
261
262
#### cache:key

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
263
264
>**Note:**
Introduced in GitLab Runner v1.0.0.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
265
266
267
268
269

The `key` directive allows you to define the affinity of caching
between jobs, allowing to have a single cache for all jobs,
cache per-job, cache per-branch or any other way you deem proper.

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
270
271
This allows you to fine tune caching, allowing you to cache data between
different jobs or even different branches.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
272

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
273
274
275
276
277
The `cache:key` variable can use any of the [predefined variables](../variables/README.md).

---

**Example configurations**
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
278
279
280

To enable per-job caching:

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
281
282
283
284
285
```yaml
cache:
  key: "$CI_BUILD_NAME"
  untracked: true
```
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
286
287
288

To enable per-branch caching:

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
289
290
291
292
293
```yaml
cache:
  key: "$CI_BUILD_REF_NAME"
  untracked: true
```
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
294
295
296

To enable per-job and per-branch caching:

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
297
298
299
300
301
```yaml
cache:
  key: "$CI_BUILD_NAME/$CI_BUILD_REF_NAME"
  untracked: true
```
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
302
303
304

To enable per-branch and per-stage caching:

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
305
306
307
308
309
```yaml
cache:
  key: "$CI_BUILD_STAGE/$CI_BUILD_REF_NAME"
  untracked: true
```
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
310

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
311
312
If you use **Windows Batch** to run your shell scripts you need to replace
`$` with `%`:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
313

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
314
315
316
317
318
```yaml
cache:
  key: "%CI_BUILD_STAGE%/%CI_BUILD_REF_NAME%"
  untracked: true
```
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
319

Douwe Maan's avatar
Douwe Maan включено в состав коммита
320
## Jobs
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
321
322
323
324

`.gitlab-ci.yml` allows you to specify an unlimited number of jobs. Each job
must have a unique name, which is not one of the Keywords mentioned above.
A job is defined by a list of parameters that define the build behavior.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341

```yaml
job_name:
  script:
    - rake spec
    - coverage
  stage: test
  only:
    - master
  except:
    - develop
  tags:
    - ruby
    - postgres
  allow_failure: true
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
342
| Keyword       | Required | Description |
Douwe Maan's avatar
Douwe Maan включено в состав коммита
343
|---------------|----------|-------------|
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
344
| script        | yes | Defines a shell script which is executed by Runner |
Pat Turner's avatar
Pat Turner включено в состав коммита
345
346
| image         | no | Use docker image, covered in [Using Docker Images](../docker/using_docker_images.md#define-image-and-services-from-gitlab-ciyml) |
| services      | no | Use docker services, covered in [Using Docker Images](../docker/using_docker_images.md#define-image-and-services-from-gitlab-ciyml) |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
347
| stage         | no | Defines a build stage (default: `test`) |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
348
| type          | no | Alias for `stage` |
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
349
| variables     | no | Define build variables on a job level |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
350
351
| only          | no | Defines a list of git refs for which build is created |
| except        | no | Defines a list of git refs for which build is not created |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
352
| tags          | no | Defines a list of tags which are used to select Runner |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
353
354
| allow_failure | no | Allow build to fail. Failed build doesn't contribute to commit status |
| when          | no | Define when to run build. Can be `on_success`, `on_failure` or `always` |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
355
| dependencies  | no | Define other builds that a build depends on so that you can pass artifacts between them|
Aurelio Jargas's avatar
Aurelio Jargas включено в состав коммита
356
| artifacts     | no | Define list of build artifacts |
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
357
| cache         | no | Define list of files that should be cached between subsequent runs |
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
358
359
| before_script | no | Override a set of commands that are executed before build |
| after_script  | no | Override a set of commands that are executed after build |
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
360
| environment   | no | Defines a name of environment to which deployment is done by this build |
Douwe Maan's avatar
Douwe Maan включено в состав коммита
361
362

### script
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
363

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
364
`script` is a shell script which is executed by the Runner. For example:
Douwe Maan's avatar
Douwe Maan включено в состав коммита
365
366
367
368
369
370
371

```yaml
job:
  script: "bundle exec rspec"
```

This parameter can also contain several commands using an array:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
372

Douwe Maan's avatar
Douwe Maan включено в состав коммита
373
374
375
376
377
378
379
380
```yaml
job:
  script:
    - uname -a
    - bundle exec rspec
```

### stage
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
381
382
383
384

`stage` allows to group build into different stages. Builds of the same `stage`
are executed in `parallel`. For more info about the use of `stage` please check
[stages](#stages).
Douwe Maan's avatar
Douwe Maan включено в состав коммита
385
386
387

### only and except

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
388
389
`only` and `except` are two parameters that set a refs policy to limit when
jobs are built:
Douwe Maan's avatar
Douwe Maan включено в состав коммита
390

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
391
392
393
394
395
396
397
398
399
400
1. `only` defines the names of branches and tags for which the job will be
    built.
2. `except` defines the names of branches and tags for which the job will
    **not** be built.

There are a few rules that apply to the usage of refs policy:

* `only` and `except` are inclusive. If both `only` and `except` are defined
   in a job specification, the ref is filtered by `only` and `except`.
* `only` and `except` allow the use of regular expressions.
Jason Roehm's avatar
Jason Roehm включено в состав коммита
401
* `only` and `except` allow the use of special keywords: `branches`, `tags`, and `triggers`.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
402
403
404
405
406
* `only` and `except` allow to specify a repository path to filter jobs for
   forks.

In the example below, `job` will run only for refs that start with `issue-`,
whereas all branches will be skipped.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
407
408
409

```yaml
job:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
410
  # use regexp
Douwe Maan's avatar
Douwe Maan включено в состав коммита
411
  only:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
412
413
    - /^issue-.*$/
  # use special keyword
Douwe Maan's avatar
Douwe Maan включено в состав коммита
414
  except:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
415
    - branches
Douwe Maan's avatar
Douwe Maan включено в состав коммита
416
417
```

Jason Roehm's avatar
Jason Roehm включено в состав коммита
418
419
420
421
422
423
424
425
426
427
428
In this example, `job` will run only for refs that are tagged, or if a build is explicitly requested
via an API trigger.

```yaml
job:
  # use special keywords
  only:
    - tags
    - triggers
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
429
430
The repository path can be used to have jobs executed only for the parent
repository and not forks:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
431
432
433
434
435
436
437
438

```yaml
job:
  only:
    - branches@gitlab-org/gitlab-ce
  except:
    - master@gitlab-org/gitlab-ce
```
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
439
440
441

The above example will run `job` for all branches on `gitlab-org/gitlab-ce`,
except master.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
442

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
443
444
445
### job variables

It is possible to define build variables using a `variables` keyword on a job
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
446
447
level. It works basically the same way as its global-level equivalent but
allows you to define job-specific build variables.
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
448

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
449
When the `variables` keyword is used on a job level, it overrides global YAML
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
450
451
build variables and predefined variables.

Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
452
453
Build variables priority is defined in
[variables documentation](../variables/README.md).
Grzegorz Bizon's avatar
Grzegorz Bizon включено в состав коммита
454

Douwe Maan's avatar
Douwe Maan включено в состав коммита
455
456
### tags

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
457
`tags` is used to select specific Runners from the list of all Runners that are
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
458
allowed to run this project.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
459

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
460
During the registration of a Runner, you can specify the Runner's tags, for
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
461
462
example `ruby`, `postgres`, `development`.

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
463
`tags` allow you to run builds with Runners that have the specified tags
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
464
465
466
assigned to them:

```yaml
Douwe Maan's avatar
Douwe Maan включено в состав коммита
467
468
469
470
471
472
job:
  tags:
    - ruby
    - postgres
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
473
The specification above, will make sure that `job` is built by a Runner that
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
474
has both `ruby` AND `postgres` tags defined.
Douwe Maan's avatar
Douwe Maan включено в состав коммита
475

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
476
### when
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
477
478
479

`when` is used to implement jobs that are run in case of failure or despite the
failure.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
480

Robert Speicher's avatar
Robert Speicher включено в состав коммита
481
482
`when` can be set to one of the following values:

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
483
1. `on_success` - execute build only when all builds from prior stages
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
484
    succeed. This is the default.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
485
1. `on_failure` - execute build only when at least one build from prior stages
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
486
487
    fails.
1. `always` - execute build regardless of the status of builds from prior stages.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
488
489
1. `manual` - execute build manually (added in GitLab 8.10). Read about
    [manual actions](#manual-actions) below.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
490

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
491
492
493
For example:

```yaml
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
494
495
496
497
498
499
500
stages:
- build
- cleanup_build
- test
- deploy
- cleanup

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
501
build_job:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
502
503
504
505
  stage: build
  script:
  - make build

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
506
cleanup_build_job:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
507
508
509
510
511
  stage: cleanup_build
  script:
  - cleanup build when failed
  when: on_failure

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
512
test_job:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
513
514
515
516
  stage: test
  script:
  - make test

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
517
deploy_job:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
518
519
520
  stage: deploy
  script:
  - make deploy
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
521
  when: manual
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
522

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
523
cleanup_job:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
524
525
526
527
528
529
530
  stage: cleanup
  script:
  - cleanup after builds
  when: always
```

The above script will:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
531

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
532
533
534
535
1. Execute `cleanup_build_job` only when `build_job` fails.
2. Always execute `cleanup_job` as the last step in pipeline regardless of
   success or failure.
3. Allow you to manually execute `deploy_job` from GitLab's UI.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
536
537
538
539
540
541

#### Manual actions

>**Note:**
Introduced in GitLab 8.10.

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
542
543
544
545
Manual actions are a special type of job that are not executed automatically;
they need to be explicitly started by a user. Manual actions can be started
from pipeline, build, environment, and deployment views. You can execute the
same manual action multiple times.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
546

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
547
An example usage of manual actions is deployment to production.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
548

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
549
550
551
### environment

>**Note:**
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
552
Introduced in GitLab 8.9.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
553

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
554
555
556
`environment` is used to define that a job deploys to a specific environment.
This allows easy tracking of all deployments to your environments straight from
GitLab.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
557

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
558
559
If `environment` is specified and no environment under that name exists, a new
one will be created automatically.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
560

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
561
562
563
The `environment` name must contain only letters, digits, '-' and '_'. Common
names are `qa`, `staging`, and `production`, but you can use whatever name works
with your workflow.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
564
565
566
567
568
569
570
571
572
573
574
575

---

**Example configurations**

```
deploy to production:
  stage: deploy
  script: git push production HEAD:master
  environment: production
```

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
576
577
The `deploy to production` job will be marked as doing deployment to
`production` environment.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
578

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
579
580
### artifacts

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
581
582
583
>**Notes:**
>
> - Introduced in GitLab Runner v0.7.0 for non-Windows platforms.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
584
> - Windows support was added in GitLab Runner v.1.0.0.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
585
> - Currently not all executors are supported.
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
586
> - Build artifacts are only collected for successful builds by default.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
587

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
588
589
`artifacts` is used to specify a list of files and directories which should be
attached to the build after success. To pass artifacts between different builds,
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
590
591
592
see [dependencies](#dependencies).

Below are some examples.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
593

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
594
Send all files in `binaries` and `.config`:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
595

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
596
597
598
599
600
601
```yaml
artifacts:
  paths:
  - binaries/
  - .config
```
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
602

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
603
Send all Git untracked files:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
604

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
605
606
607
608
609
```yaml
artifacts:
  untracked: true
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
610
Send all Git untracked files and files in `binaries`:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
611

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
612
613
614
615
616
617
```yaml
artifacts:
  untracked: true
  paths:
  - binaries/
```
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
618

Mart Sõmermaa's avatar
Mart Sõmermaa включено в состав коммита
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
You may want to create artifacts only for tagged releases to avoid filling the
build server storage with temporary build artifacts.

Create artifacts only for tags (`default-job` will not create artifacts):

```yaml
default-job:
  script:
    - mvn test -U
  except:
    - tags

release-job:
  script:
    - mvn package -U
  artifacts:
    paths:
    - target/*.war
  only:
    - tags
```

Mart Somermaa's avatar
Mart Somermaa включено в состав коммита
641
642
The artifacts will be sent to GitLab after a successful build and will
be available for download in the GitLab UI.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
643

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
644
645
#### artifacts:name

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
646
647
>**Note:**
Introduced in GitLab 8.6 and GitLab Runner v1.1.0.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
648

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
649
The `name` directive allows you to define the name of the created artifacts
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
650
archive. That way, you can have a unique name for every archive which could be
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
651
652
useful when you'd like to download the archive from GitLab. The `artifacts:name`
variable can make use of any of the [predefined variables](../variables/README.md).
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
653
The default name is `artifacts`, which becomes `artifacts.zip` when downloaded.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
654
655
656
657
658

---

**Example configurations**

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
659
To create an archive with a name of the current build:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
660
661
662
663
664
665
666

```yaml
job:
  artifacts:
    name: "$CI_BUILD_NAME"
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
667
668
To create an archive with a name of the current branch or tag including only
the files that are untracked by Git:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
669
670
671
672
673
674
675
676

```yaml
job:
   artifacts:
     name: "$CI_BUILD_REF_NAME"
     untracked: true
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
677
678
To create an archive with a name of the current build and the current branch or
tag including only the files that are untracked by Git:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
679
680
681
682
683
684
685
686

```yaml
job:
  artifacts:
    name: "${CI_BUILD_NAME}_${CI_BUILD_REF_NAME}"
    untracked: true
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
687
To create an archive with a name of the current [stage](#stages) and branch name:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
688
689
690
691
692
693
694
695

```yaml
job:
  artifacts:
    name: "${CI_BUILD_STAGE}_${CI_BUILD_REF_NAME}"
    untracked: true
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
696
697
---

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
698
699
700
701
702
703
704
705
706
707
If you use **Windows Batch** to run your shell scripts you need to replace
`$` with `%`:

```yaml
job:
  artifacts:
    name: "%CI_BUILD_STAGE%_%CI_BUILD_REF_NAME%"
    untracked: true
```

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
708
709
710
711
712
713
714
715
716
717
#### artifacts:when

>**Note:**
Introduced in GitLab 8.9 and GitLab Runner v1.3.0.

`artifacts:when` is used to upload artifacts on build failure or despite the
failure.

`artifacts:when` can be set to one of the following values:

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
718
719
720
1. `on_success` - upload artifacts only when the build succeeds. This is the default.
1. `on_failure` - upload artifacts only when the build fails.
1. `always` - upload artifacts regardless of the build status.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
721
722
723
724
725

---

**Example configurations**

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
726
To upload artifacts only when build fails.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
727
728
729
730
731
732
733

```yaml
job:
  artifacts:
    when: on_failure
```

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
734
735
736
737
738
#### artifacts:expire_in

>**Note:**
Introduced in GitLab 8.9 and GitLab Runner v1.3.0.

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
739
740
741
742
`artifacts:expire_in` is used to delete uploaded artifacts after the specified
time. By default, artifacts are stored on GitLab forever. `expire_in` allows you
to specify how long artifacts should live before they expire, counting from the
time they are uploaded and stored on GitLab.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
743

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
744
745
You can use the **Keep** button on the build page to override expiration and
keep artifacts forever.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
746

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
747
748
After expiry, artifacts are actually deleted hourly by default (via a cron job),
but they are not accessible after expiry.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
749

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
750
The value of `expire_in` is an elapsed time. Examples of parseable values:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
751
752
753
754
755
756
757
758
759
760
761
- '3 mins 4 sec'
- '2 hrs 20 min'
- '2h20min'
- '6 mos 1 day'
- '47 yrs 6 mos and 4d'
- '3 weeks and 2 days'

---

**Example configurations**

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
762
To expire artifacts 1 week after being uploaded:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
763
764
765
766
767
768
769

```yaml
job:
  artifacts:
    expire_in: 1 week
```

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
770
771
### dependencies

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
772
773
>**Note:**
Introduced in GitLab 8.6 and GitLab Runner v1.1.1.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
774

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
775
776
This feature should be used in conjunction with [`artifacts`](#artifacts) and
allows you to define the artifacts to pass between different builds.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
777

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
778
Note that `artifacts` from all previous [stages](#stages) are passed by default.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
779

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
780
To use this feature, define `dependencies` in context of the job and pass
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
781
a list of all previous builds from which the artifacts should be downloaded.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
782
783
You can only define builds from stages that are executed before the current one.
An error will be shown if you define builds from the current stage or next ones.
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
784
Defining an empty array will skip downloading any artifacts for that job.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
785
786

---
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
787

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
788
789
790
791
792
793
794
In the following example, we define two jobs with artifacts, `build:osx` and
`build:linux`. When the `test:osx` is executed, the artifacts from `build:osx`
will be downloaded and extracted in the context of the build. The same happens
for `test:linux` and artifacts from `build:linux`.

The job `deploy` will download artifacts from all previous builds because of
the [stage](#stages) precedence:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
795

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
796
```yaml
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
797
798
build:osx:
  stage: build
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
799
  script: make build:osx
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
800
801
802
  artifacts:
    paths:
    - binaries/
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
803

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
804
805
build:linux:
  stage: build
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
806
  script: make build:linux
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
807
808
809
810
811
812
  artifacts:
    paths:
    - binaries/

test:osx:
  stage: test
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
813
  script: make test:osx
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
814
815
816
817
818
  dependencies:
  - build:osx

test:linux:
  stage: test
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
819
  script: make test:linux
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
820
821
822
823
824
  dependencies:
  - build:linux

deploy:
  stage: deploy
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
825
  script: make deploy
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
826
827
```

Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
828
829
830
831
832
### before_script and after_script

It's possible to overwrite globally defined `before_script` and `after_script`:

```yaml
Philipp Kraus's avatar
Philipp Kraus включено в состав коммита
833
before_script:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
834
835
836
837
838
839
840
841
842
843
844
- global before script

job:
  before_script:
  - execute this instead of global before script
  script:
  - my command
  after_script:
  - execute this after my script
```

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
845
846
847
## Git Strategy

>**Note:**
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
848
849
Introduced in GitLab 8.9 as an experimental feature. May change in future
releases or be removed completely.
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
850
851
852

You can set the `GIT_STRATEGY` used for getting recent application code. `clone`
is slower, but makes sure you have a clean directory before every build. `fetch`
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
853
854
855
is faster. `GIT_STRATEGY` can be specified in the global `variables` section or
in the `variables` section for individual jobs. If it's not specified, then the
default from project settings will be used.
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871

```
variables:
  GIT_STRATEGY: clone
```

or

```
variables:
  GIT_STRATEGY: fetch
```

## Shallow cloning

>**Note:**
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
872
873
Introduced in GitLab 8.9 as an experimental feature. May change in future
releases or be removed completely.
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
874
875

You can specify the depth of fetching and cloning using `GIT_DEPTH`. This allows
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
876
877
878
shallow cloning of the repository which can significantly speed up cloning for
repositories with a large number of commits or old, large binaries. The value is
passed to `git fetch` and `git clone`.
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
879

Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
>**Note:**
If you use a depth of 1 and have a queue of builds or retry
builds, jobs may fail.

Since Git fetching and cloning is based on a ref, such as a branch name, runners
can't clone a specific commit SHA. If there are multiple builds in the queue, or
you are retrying an old build, the commit to be tested needs to be within the
git history that is cloned. Setting too small a value for `GIT_DEPTH` can make
it impossible to run these old commits. You will see `unresolved reference` in
build logs. You should then reconsider changing `GIT_DEPTH` to a higher value.

Builds that rely on `git describe` may not work correctly when `GIT_DEPTH` is
set since only part of the git history is present.

To fetch or clone only the last 3 commits:
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
895
896
```
variables:
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
897
  GIT_DEPTH: "3"
Mark Pundsack's avatar
Mark Pundsack включено в состав коммита
898
899
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
## Hidden jobs

>**Note:**
Introduced in GitLab 8.6 and GitLab Runner v1.1.1.

Jobs that start with a dot (`.`) will be not processed by GitLab CI. You can
use this feature to ignore jobs, or use the
[special YAML features](#special-yaml-features) and transform the hidden jobs
into templates.

In the following example, `.job_name` will be ignored:

```yaml
.job_name:
  script:
    - rake spec
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
918
## Special YAML features
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
919

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
920
921
922
It's possible to use special YAML features like anchors (`&`), aliases (`*`)
and map merging (`<<`), which will allow you to greatly reduce the complexity
of `.gitlab-ci.yml`.
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
923

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
924
Read more about the various [YAML features](https://learnxinyminutes.com/docs/yaml/).
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
925

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
926
927
928
929
930
931
932
933
934
935
936
937
938
### Anchors

>**Note:**
Introduced in GitLab 8.6 and GitLab Runner v1.1.1.

YAML also has a handy feature called 'anchors', which let you easily duplicate
content across your document. Anchors can be used to duplicate/inherit
properties, and is a perfect example to be used with [hidden jobs](#hidden-jobs)
to provide templates for your jobs.

The following example uses anchors and map merging. It will create two jobs,
`test1` and `test2`, that will inherit the parameters of `.job_template`, each
having their own custom `script` defined:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
939
940

```yaml
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
941
.job_template: &job_definition  # Hidden job that defines an anchor named 'job_definition'
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
942
943
944
945
946
947
  image: ruby:2.1
  services:
    - postgres
    - redis

test1:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
948
  <<: *job_definition           # Merge the contents of the 'job_definition' alias
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
949
  script:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
950
    - test1 project
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
951
952

test2:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
953
  <<: *job_definition           # Merge the contents of the 'job_definition' alias
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
954
  script:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
    - test2 project
```

`&` sets up the name of the anchor (`job_definition`), `<<` means "merge the
given hash into the current one", and `*` includes the named anchor
(`job_definition` again). The expanded version looks like this:

```yaml
.job_template:
  image: ruby:2.1
  services:
    - postgres
    - redis

test1:
  image: ruby:2.1
  services:
    - postgres
    - redis
  script:
    - test1 project

test2:
  image: ruby:2.1
  services:
    - postgres
    - redis
  script:
    - test2 project
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
984
985
```

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
986
987
988
989
Let's see another one example. This time we will use anchors to define two sets
of services. This will create two jobs, `test:postgres` and `test:mysql`, that
will share the `script` directive defined in `.job_template`, and the `services`
directive defined in `.postgres_services` and `.mysql_services` respectively:
Kamil Trzcinski's avatar
Kamil Trzcinski включено в состав коммита
990
991
992
993
994
995
996
997
998
999
1000

```yaml
.job_template: &job_definition
  script:
    - test project

.postgres_services:
  services: &postgres_definition
    - postgres
    - ruby

Для ускорения просмотра не вся история отображается Просмотреть всю вину