Commit 425c041e authored by Marcel Amirault's avatar Marcel Amirault

Merge branch 'patch-38' into 'master'

docs update config ref to include example using YAML anchors for base-variables

See merge request gitlab-org/gitlab!20556
parents 5cc4a92b 164ba7fa
......@@ -203,7 +203,7 @@ job:
You can use [YAML anchors](#anchors) with scripts, which makes it possible to
include a predefined list of commands in multiple jobs.
Example:
For example:
```yaml
.something: &something
......@@ -1413,6 +1413,11 @@ Also in the example, `GIT_STRATEGY` is set to `none` so that GitLab Runner won
try to check out the code after the branch is deleted when the `stop_review_app`
job is [automatically triggered](../environments.md#automatically-stopping-an-environment).
NOTE: **Note:**
The above example overwrites global variables. If your stop environment job depends
on global variables, you can use [anchor variables](#yaml-anchors-for-variables) when setting the `GIT_STRATEGY`
to change it without overriding the global variables.
The `stop_review_app` job is **required** to have the following keywords defined:
- `when` - [reference](#when)
......@@ -3159,6 +3164,29 @@ which can be set in GitLab's UI.
Learn more about [variables and their priority][variables].
#### YAML anchors for variables
[YAML anchors](#anchors) can be used with `variables`, to easily repeat assignment
of variables across multiple jobs. It can also enable more flexibility when a job
requires a specific `variables` block that would otherwise override the global variables.
In the example below, we will override the `GIT_STRATEGY` variable without affecting
the use of the `SAMPLE_VARIABLE` variable:
```yaml
# global variables
variables: &global-variables
SAMPLE_VARIABLE: sample_variable_value
# a job that needs to set the GIT_STRATEGY variable, yet depend on global variables
job_no_git_strategy:
stage: cleanup
variables:
<<: *global-variables
GIT_STRATEGY: none
script: echo $SAMPLE_VARIABLE
```
#### Git strategy
> Introduced in GitLab 8.9 as an experimental feature. May change or be removed
......
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