-`script` does not merge, but `script: ['rake rspec']` overwrites
`script: ['echo "Hello world!"']`. You can use [YAML anchors](yaml_specific_features.md#anchors) to merge arrays.
##### Exclude a key from `extends`
To exclude a key from the extended content, you must assign it to `null`, for example:
```yaml
.base:
script:test
variables:
VAR1:base var 1
test1:
extends:.base
variables:
VAR1:test1 var 1
VAR2:test2 var 2
test2:
extends:.base
variables:
VAR2:test2 var 2
test3:
extends:.base
variables:{}
test4:
extends:.base
variables:null
```
Merged configuration:
```yaml
test1:
script:test
variables:
VAR1:test1 var 1
VAR2:test2 var 2
test2:
script:test
variables:
VAR1:base var 1
VAR2:test2 var 2
test3:
script:test
variables:
VAR1:base var 1
test4:
script:test
variables:null
```
#### Use `extends` and `include` together
To reuse configuration from different configuration files,
combine `extends` and [`include`](#include).
In the following example, a `script` is defined in the `included.yml` file.
Then, in the `.gitlab-ci.yml` file, `extends` refers
to the contents of the `script`:
-`included.yml`:
```yaml
.template:
script:
-echo Hello!
```
**Additional details:**
-`.gitlab-ci.yml`:
- In GitLab 12.0 and later, you can use multiple parents for `extends`.
- The `extends` keyword supports up to eleven levels of inheritance, but you should
avoid using more than three levels.
- In the example above, `.tests` is a [hidden job](../jobs/index.md#hide-jobs),
but you can extend configuration from regular jobs as well.
```yaml
include:included.yml
**Related topics:**
useTemplate:
image:alpine
extends:.template
```
-[Reuse configuration sections by using `extends`](yaml_optimization.md#use-extends-to-reuse-configuration-sections).
- Use `extends` to reuse configuration from [included configuration files](yaml_optimization.md#use-extends-and-include-together).
### `rules`
...
...
@@ -1116,7 +960,7 @@ The job is not added to the pipeline:
- If no rules match.
- If a rule matches and has `when: never`.
You can use [`!reference` tags](yaml_specific_features.md#reference-tags) to [reuse `rules` configuration](../jobs/job_control.md#reuse-rules-in-different-jobs)
You can use [`!reference` tags](yaml_optimization.md#reference-tags) to [reuse `rules` configuration](../jobs/job_control.md#reuse-rules-in-different-jobs)
in different jobs.
#### `rules:if`
...
...
@@ -2162,7 +2006,7 @@ Also in the example, `GIT_STRATEGY` is set to `none`. If the
the runner won't try to check out the code after the branch is deleted.
The example also overwrites global variables. If your `stop``environment` job depends
on global variables, use [anchor variables](yaml_specific_features.md#yaml-anchors-for-variables) when you set the `GIT_STRATEGY`
on global variables, use [anchor variables](yaml_optimization.md#yaml-anchors-for-variables) when you set the `GIT_STRATEGY`
to change the job without overriding the global variables.
The `stop_review_app` job is **required** to have the following keywords defined:
...
...
@@ -4186,7 +4030,7 @@ deploy_review_job:
**Related topics**:
- You can use [YAML anchors for variables](yaml_specific_features.md#yaml-anchors-for-variables).
- You can use [YAML anchors for variables](yaml_optimization.md#yaml-anchors-for-variables).
-[Predefined variables](../variables/predefined_variables.md) are variables the runner
automatically creates and makes available in the job.
- You can [configure runner behavior with variables](../runners/configure_runners.md#configure-runner-behavior-with-variables).