Commit de0c9d8e authored by Suzanne Selhorn's avatar Suzanne Selhorn

Merge branch 'docs-inherit-keyword-style' into 'master'

Update inherit keyword to new reference style

See merge request gitlab-org/gitlab!74059
parents c67b571a fb7743a1
...@@ -168,17 +168,74 @@ file: ...@@ -168,17 +168,74 @@ file:
- Start the job name with a dot (`.`) and it is not processed by GitLab CI/CD: - Start the job name with a dot (`.`) and it is not processed by GitLab CI/CD:
```yaml ```yaml
.hidden_job: .hidden_job:
script: script:
- run test - run test
``` ```
You can use hidden jobs that start with `.` as templates for reusable configuration with: You can use hidden jobs that start with `.` as templates for reusable configuration with:
- The [`extends` keyword](../yaml/index.md#extends). - The [`extends` keyword](../yaml/index.md#extends).
- [YAML anchors](../yaml/yaml_specific_features.md#anchors). - [YAML anchors](../yaml/yaml_specific_features.md#anchors).
## Control the inheritance of default keywords and global variables
You can control the inheritance of:
- [default keywords](../yaml/index.md#default) with [`inherit:default`](../yaml/index.md#inheritdefault).
- [global variables](../yaml/index.md#default) with [`inherit:variables`](../yaml/index.md#inheritvariables).
For example:
```yaml
default:
image: 'ruby:2.4'
before_script:
- echo Hello World
variables:
DOMAIN: example.com
WEBHOOK_URL: https://my-webhook.example.com
rubocop:
inherit:
default: false
variables: false
script: bundle exec rubocop
rspec:
inherit:
default: [image]
variables: [WEBHOOK_URL]
script: bundle exec rspec
capybara:
inherit:
variables: false
script: bundle exec capybara
karma:
inherit:
default: true
variables: [DOMAIN]
script: karma
```
In this example:
- `rubocop`:
- inherits: Nothing.
- `rspec`:
- inherits: the default `image` and the `WEBHOOK_URL` variable.
- does **not** inherit: the default `before_script` and the `DOMAIN` variable.
- `capybara`:
- inherits: the default `before_script` and `image`.
- does **not** inherit: the `DOMAIN` and `WEBHOOK_URL` variables.
- `karma`:
- inherits: the default `image` and `before_script`, and the `DOMAIN` variable.
- does **not** inherit: `WEBHOOK_URL` variable.
## Specifying variables when running manual jobs ## Specifying variables when running manual jobs
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/30485) in GitLab 12.2. > [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/30485) in GitLab 12.2.
......
...@@ -154,7 +154,7 @@ trigger-downstream: ...@@ -154,7 +154,7 @@ trigger-downstream:
trigger: my/project trigger: my/project
``` ```
You can stop global variables from reaching the downstream pipeline by using the [`inherit` keyword](../yaml/index.md#inherit). You can stop global variables from reaching the downstream pipeline by using the [`inherit:variables` keyword](../yaml/index.md#inheritvariables).
In this example, the `MY_GLOBAL_VAR` variable is not available in the triggered pipeline: In this example, the `MY_GLOBAL_VAR` variable is not available in the triggered pipeline:
```yaml ```yaml
......
...@@ -114,6 +114,7 @@ a job-specific `image:` section: ...@@ -114,6 +114,7 @@ a job-specific `image:` section:
that keyword defined. that keyword defined.
- If a job already has one of the keywords configured, the configuration in the job - If a job already has one of the keywords configured, the configuration in the job
takes precedence and is not replaced by the default. takes precedence and is not replaced by the default.
- Control inheritance of default keywords in jobs with [`inherit:default`](#inheritdefault).
### `stages` ### `stages`
...@@ -4191,84 +4192,80 @@ You must: ...@@ -4191,84 +4192,80 @@ You must:
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/207484) in GitLab 12.9. > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/207484) in GitLab 12.9.
Use `inherit:` to control inheritance of globally-defined defaults Use `inherit:` to [control inheritance of globally-defined defaults and variables](../jobs/index.md#control-the-inheritance-of-default-keywords-and-global-variables).
and variables.
To enable or disable the inheritance of all `default:` or `variables:` keywords, use: #### `inherit:default`
- `default: true` or `default: false` Use `inherit:default` to control the inheritance of [default keywords](#default).
- `variables: true` or `variables: false`
To inherit only a subset of `default:` keywords or `variables:`, specify what **Keyword type**: Job keyword. You can use it only as part of a job.
you wish to inherit. Anything not listed is **not** inherited. Use
one of the following formats:
```yaml
inherit:
default: [keyword1, keyword2]
variables: [VARIABLE1, VARIABLE2]
```
Or:
```yaml **Possible inputs**:
inherit:
default:
- keyword1
- keyword2
variables:
- VARIABLE1
- VARIABLE2
```
In the following example: - `true` (default) or `false` to enable or disable the inheritance of all default keywords.
- A list of specific default keywords to inherit.
- `rubocop`: **Example of `inherit:default`:**
- inherits: Nothing.
- `rspec`:
- inherits: the default `image` and the `WEBHOOK_URL` variable.
- does **not** inherit: the default `before_script` and the `DOMAIN` variable.
- `capybara`:
- inherits: the default `before_script` and `image`.
- does **not** inherit: the `DOMAIN` and `WEBHOOK_URL` variables.
- `karma`:
- inherits: the default `image` and `before_script`, and the `DOMAIN` variable.
- does **not** inherit: `WEBHOOK_URL` variable.
```yaml ```yaml
default: default:
image: 'ruby:2.4' retry: 2
before_script: image: ruby:3.0
- echo Hello World interruptible: true
variables:
DOMAIN: example.com
WEBHOOK_URL: https://my-webhook.example.com
rubocop: job1:
script: echo "This job does not inherit any default keywords."
inherit: inherit:
default: false default: false
variables: false
script: bundle exec rubocop
rspec: job2:
script: echo "This job inherits only the two listed default keywords. It does not inherit 'interruptible'."
inherit: inherit:
default: [image] default:
variables: [WEBHOOK_URL] - retry
script: bundle exec rspec - image
```
**Additional details:**
- You can also list default keywords to inherit on one line: `default: [keyword1, keyword2]`
#### `inherit:variables`
Use `inherit:variables` to control the inheritance of [global variables](#variables) keywords.
**Keyword type**: Job keyword. You can use it only as part of a job.
**Possible inputs**:
- `true` (default) or `false` to enable or disable the inheritance of all global variables.
- A list of specific variables to inherit.
capybara: **Example of `inherit:variables`:**
```yaml
variables:
VARIABLE1: "This is variable 1"
VARIABLE2: "This is variable 2"
VARIABLE3: "This is variable 3"
job1:
script: echo "This job does not inherit any global variables."
inherit: inherit:
variables: false variables: false
script: bundle exec capybara
karma: job2:
script: echo "This job inherits only the two listed global variables. It does not inherit 'VARIABLE3'."
inherit: inherit:
default: true variables:
variables: [DOMAIN] - VARIABLE1
script: karma - VARIABLE2
``` ```
**Additional details:**
- You can also list global variables to inherit on one line: `variables: [VARIABLE1, VARIABLE2]`
## `variables` ## `variables`
> Introduced in GitLab Runner v0.5.0. > Introduced in GitLab Runner v0.5.0.
......
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