Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3f9b79ce
Commit
3f9b79ce
authored
Jul 02, 2020
by
Ben Bodenmiller
Committed by
Evan Read
Jul 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GitLab CI: Improve include, extends, & YAML anchors details
parent
333c6d55
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
7 deletions
+39
-7
doc/ci/yaml/README.md
doc/ci/yaml/README.md
+39
-7
No files found.
doc/ci/yaml/README.md
View file @
3f9b79ce
...
@@ -383,7 +383,7 @@ NOTE: **Note:**
...
@@ -383,7 +383,7 @@ NOTE: **Note:**
The configuration is a snapshot in time and persisted in the database. Any changes to
The configuration is a snapshot in time and persisted in the database. Any changes to
referenced
`.gitlab-ci.yml`
configuration won't be reflected in GitLab until the next pipeline is created.
referenced
`.gitlab-ci.yml`
configuration won't be reflected in GitLab until the next pipeline is created.
The files defined
in
`include`
are:
The files defined
by
`include`
are:
-
Deep merged with those in
`.gitlab-ci.yml`
.
-
Deep merged with those in
`.gitlab-ci.yml`
.
-
Always evaluated first and merged with the content of
`.gitlab-ci.yml`
,
-
Always evaluated first and merged with the content of
`.gitlab-ci.yml`
,
...
@@ -391,11 +391,11 @@ The files defined in `include` are:
...
@@ -391,11 +391,11 @@ The files defined in `include` are:
TIP:
**Tip:**
TIP:
**Tip:**
Use merging to customize and override included CI/CD configurations with local
Use merging to customize and override included CI/CD configurations with local
definitions.
definitions.
Local definitions in
`.gitlab-ci.yml`
will override included definitions.
NOTE:
**Note:**
NOTE:
**Note:**
Using
YAML aliases
across different YAML files sourced by
`include`
is not
Using
[
YAML anchors
](
#anchors
)
across different YAML files sourced by
`include`
is not
supported. You must only refer to a
liase
s in the same file. Instead
supported. You must only refer to a
nchor
s in the same file. Instead
of using YAML anchors, you can use the
[
`extends` keyword
](
#extends
)
.
of using YAML anchors, you can use the
[
`extends` keyword
](
#extends
)
.
#### `include:local`
#### `include:local`
...
@@ -972,24 +972,38 @@ spinach:
...
@@ -972,24 +972,38 @@ spinach:
```
```
In GitLab 12.0 and later, it's also possible to use multiple parents for
In GitLab 12.0 and later, it's also possible to use multiple parents for
`extends`
. The algorithm used for merge is "closest scope wins", so
`extends`
.
keys from the last member will always shadow anything defined on other
#### Merge details
`extends`
is able to merge hashes but not arrays.
The algorithm used for merge is "closest scope wins", so
keys from the last member will always override anything defined on other
levels. For example:
levels. For example:
```
yaml
```
yaml
.only-important
:
.only-important
:
variables
:
URL
:
"
http://my-url.internal"
IMPORTANT_VAR
:
"
the
details"
only
:
only
:
-
master
-
master
-
stable
-
stable
tags
:
tags
:
-
production
-
production
script
:
-
echo "Hello world!"
.in-docker
:
.in-docker
:
variables
:
URL
:
"
http://docker-url.internal"
tags
:
tags
:
-
docker
-
docker
image
:
alpine
image
:
alpine
rspec
:
rspec
:
variables
:
GITLAB
:
"
is-awesome"
extends
:
extends
:
-
.only-important
-
.only-important
-
.in-docker
-
.in-docker
...
@@ -1001,6 +1015,10 @@ This results in the following `rspec` job:
...
@@ -1001,6 +1015,10 @@ This results in the following `rspec` job:
```
yaml
```
yaml
rspec
:
rspec
:
variables
:
URL
:
"
http://docker-url.internal"
IMPORTANT_VAR
:
"
the
details"
GITLAB
:
"
is-awesome"
only
:
only
:
-
master
-
master
-
stable
-
stable
...
@@ -1011,6 +1029,15 @@ rspec:
...
@@ -1011,6 +1029,15 @@ rspec:
-
rake rspec
-
rake rspec
```
```
Note that in the example above:
-
`variables`
sections have been merged but that
`URL: "http://my-url.internal"`
has been overwritten by
`URL: "http://docker-url.internal"`
.
-
`tags: ['production']`
has been overwritten by
`tags: ['docker']`
.
-
`script`
has not been merged but rather
`script: ['echo "Hello world!"']`
has
been overwritten by
`script: ['rake rspec']`
. Arrays can be
merged using
[
YAML anchors
](
#anchors
)
.
#### Using `extends` and `include` together
#### Using `extends` and `include` together
`extends`
works across configuration files combined with
`include`
.
`extends`
works across configuration files combined with
`include`
.
...
@@ -4149,6 +4176,10 @@ of `.gitlab-ci.yml`.
...
@@ -4149,6 +4176,10 @@ of `.gitlab-ci.yml`.
Read more about the various
[
YAML features
](
https://learnxinyminutes.com/docs/yaml/
)
.
Read more about the various
[
YAML features
](
https://learnxinyminutes.com/docs/yaml/
)
.
In most cases, the
[
`extends` keyword
](
#extends
)
is more user friendly and should
be used over these special YAML features. YAML anchors may still
need to be used to merge arrays.
### Anchors
### Anchors
> Introduced in GitLab 8.6 and GitLab Runner v1.1.1.
> Introduced in GitLab 8.6 and GitLab Runner v1.1.1.
...
@@ -4273,7 +4304,8 @@ You can see that the hidden jobs are conveniently used as templates.
...
@@ -4273,7 +4304,8 @@ You can see that the hidden jobs are conveniently used as templates.
NOTE:
**Note:**
NOTE:
**Note:**
You can't use YAML anchors across multiple files when leveraging the
[
`include`
](
#include
)
You can't use YAML anchors across multiple files when leveraging the
[
`include`
](
#include
)
feature. Anchors are only valid within the file they were defined in.
feature. Anchors are only valid within the file they were defined in. Instead
of using YAML anchors, you can use the
[
`extends` keyword
](
#extends
)
.
#### YAML anchors for `before_script` and `after_script`
#### YAML anchors for `before_script` and `after_script`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment