Commit e0e69938 authored by Evan Read's avatar Evan Read

Merge branch 'patch-120' into 'master'

Provide merging details and example for YAML Anchors

See merge request gitlab-org/gitlab!32913
parents a6b0dffc b3c5e4e5
...@@ -4187,7 +4187,8 @@ need to be used to merge arrays. ...@@ -4187,7 +4187,8 @@ need to be used to merge arrays.
YAML has a handy feature called 'anchors', which lets you easily duplicate YAML has a handy feature called 'anchors', which lets you easily duplicate
content across your document. Anchors can be used to duplicate/inherit content across your document. Anchors can be used to duplicate/inherit
properties, and is a perfect example to be used with [hidden jobs](#hide-jobs) properties, and is a perfect example to be used with [hidden jobs](#hide-jobs)
to provide templates for your jobs. to provide templates for your jobs. When there is duplicate keys, GitLab will
perform a reverse deep merge based on the keys.
The following example uses anchors and map merging. It will create two 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 `test1` and `test2`, that will inherit the parameters of `.job_template`, each
...@@ -4248,6 +4249,8 @@ directive defined in `.postgres_services` and `.mysql_services` respectively: ...@@ -4248,6 +4249,8 @@ directive defined in `.postgres_services` and `.mysql_services` respectively:
.job_template: &job_definition .job_template: &job_definition
script: script:
- test project - test project
tags:
- dev
.postgres_services: .postgres_services:
services: &postgres_definition services: &postgres_definition
...@@ -4262,6 +4265,8 @@ directive defined in `.postgres_services` and `.mysql_services` respectively: ...@@ -4262,6 +4265,8 @@ directive defined in `.postgres_services` and `.mysql_services` respectively:
test:postgres: test:postgres:
<<: *job_definition <<: *job_definition
services: *postgres_definition services: *postgres_definition
tags:
- postgres
test:mysql: test:mysql:
<<: *job_definition <<: *job_definition
...@@ -4274,6 +4279,8 @@ The expanded version looks like this: ...@@ -4274,6 +4279,8 @@ The expanded version looks like this:
.job_template: .job_template:
script: script:
- test project - test project
tags:
- dev
.postgres_services: .postgres_services:
services: services:
...@@ -4291,6 +4298,8 @@ test:postgres: ...@@ -4291,6 +4298,8 @@ test:postgres:
services: services:
- postgres - postgres
- ruby - ruby
tags:
- postgres
test:mysql: test:mysql:
script: script:
...@@ -4298,10 +4307,15 @@ test:mysql: ...@@ -4298,10 +4307,15 @@ test:mysql:
services: services:
- mysql - mysql
- ruby - ruby
tags:
- dev
``` ```
You can see that the hidden jobs are conveniently used as templates. You can see that the hidden jobs are conveniently used as templates.
NOTE: **Note:**
Note that `tags: [dev]` has been overwritten by `tags: [postgres]`.
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. Instead feature. Anchors are only valid within the file they were defined in. Instead
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment