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
YAML has a handy feature called 'anchors', which lets 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](#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,
`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:
.job_template: &job_definition
script:
- test project
tags:
- dev
.postgres_services:
services: &postgres_definition
......@@ -4231,6 +4234,8 @@ directive defined in `.postgres_services` and `.mysql_services` respectively:
test:postgres:
<<: *job_definition
services: *postgres_definition
tags:
- postgres
test:mysql:
<<: *job_definition
......@@ -4243,6 +4248,8 @@ The expanded version looks like this:
.job_template:
script:
- test project
tags:
- dev
.postgres_services:
services:
......@@ -4260,6 +4267,8 @@ test:postgres:
services:
- postgres
- ruby
tags:
- postgres
test:mysql:
script:
......@@ -4267,10 +4276,15 @@ test:mysql:
services:
- mysql
- ruby
tags:
- dev
```
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:**
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.
......
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