Commit b3c5e4e5 authored by Ben Bodenmiller's avatar Ben Bodenmiller Committed by Evan Read

Provide merging details and example for YAML Anchors

parent 8a26748d
...@@ -4156,7 +4156,8 @@ Read more about the various [YAML features](https://learnxinyminutes.com/docs/ya ...@@ -4156,7 +4156,8 @@ Read more about the various [YAML features](https://learnxinyminutes.com/docs/ya
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
...@@ -4217,6 +4218,8 @@ directive defined in `.postgres_services` and `.mysql_services` respectively: ...@@ -4217,6 +4218,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
...@@ -4231,6 +4234,8 @@ directive defined in `.postgres_services` and `.mysql_services` respectively: ...@@ -4231,6 +4234,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
...@@ -4243,6 +4248,8 @@ The expanded version looks like this: ...@@ -4243,6 +4248,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:
...@@ -4260,6 +4267,8 @@ test:postgres: ...@@ -4260,6 +4267,8 @@ test:postgres:
services: services:
- postgres - postgres
- ruby - ruby
tags:
- postgres
test:mysql: test:mysql:
script: script:
...@@ -4267,10 +4276,15 @@ test:mysql: ...@@ -4267,10 +4276,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. feature. Anchors are only valid within the file they were defined in.
......
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