diff options
Diffstat (limited to 'doc/ci/yaml')
-rw-r--r-- | doc/ci/yaml/README.md | 974 | ||||
-rw-r--r-- | doc/ci/yaml/img/ci_config_visualization_hover_v13_5.png | bin | 0 -> 30986 bytes | |||
-rw-r--r-- | doc/ci/yaml/img/ci_config_visualization_v13_5.png | bin | 0 -> 30319 bytes | |||
-rw-r--r-- | doc/ci/yaml/includes.md | 9 | ||||
-rw-r--r-- | doc/ci/yaml/visualization.md | 46 |
5 files changed, 566 insertions, 463 deletions
diff --git a/doc/ci/yaml/README.md b/doc/ci/yaml/README.md index 40df9c7c986..2e4ab68a0e8 100644 --- a/doc/ci/yaml/README.md +++ b/doc/ci/yaml/README.md @@ -33,11 +33,8 @@ We have complete examples of configuring pipelines: > - <i class="fa fa-youtube-play youtube" aria-hidden="true"></i> Learn how [Verizon reduced rebuilds](https://about.gitlab.com/blog/2019/02/14/verizon-customer-story/) > from 30 days to under 8 hours with GitLab. -NOTE: **Note:** If you have a [mirrored repository that GitLab pulls from](../../user/project/repository/repository_mirroring.md#pulling-from-a-remote-repository), -you may need to enable pipeline triggering. Go to your project's - -**Settings > Repository > Pull from a remote repository > Trigger pipelines for mirror updates**. +you may need to enable pipeline triggering. Go to your project's **Settings > Repository > Pull from a remote repository > Trigger pipelines for mirror updates**. ## Introduction @@ -107,12 +104,12 @@ The following table lists available parameters for jobs: | [`script`](#script) | Shell script that is executed by a runner. | | [`after_script`](#before_script-and-after_script) | Override a set of commands that are executed after job. | | [`allow_failure`](#allow_failure) | Allow job to fail. Failed job does not contribute to commit status. | -| [`artifacts`](#artifacts) | List of files and directories to attach to a job on success. Also available: `artifacts:paths`, `artifacts:exclude`, `artifacts:expose_as`, `artifacts:name`, `artifacts:untracked`, `artifacts:when`, `artifacts:expire_in`, `artifacts:reports`. | +| [`artifacts`](#artifacts) | List of files and directories to attach to a job on success. Also available: `artifacts:paths`, `artifacts:exclude`, `artifacts:expose_as`, `artifacts:name`, `artifacts:untracked`, `artifacts:when`, `artifacts:expire_in`, and `artifacts:reports`. | | [`before_script`](#before_script-and-after_script) | Override a set of commands that are executed before job. | -| [`cache`](#cache) | List of files that should be cached between subsequent runs. Also available: `cache:paths`, `cache:key`, `cache:untracked`, and `cache:policy`. | +| [`cache`](#cache) | List of files that should be cached between subsequent runs. Also available: `cache:paths`, `cache:key`, `cache:untracked`, `cache:when`, and `cache:policy`. | | [`coverage`](#coverage) | Code coverage settings for a given job. | | [`dependencies`](#dependencies) | Restrict which artifacts are passed to a specific job by providing a list of jobs to fetch artifacts from. | -| [`environment`](#environment) | Name of an environment to which the job deploys. Also available: `environment:name`, `environment:url`, `environment:on_stop`, `environment:auto_stop_in` and `environment:action`. | +| [`environment`](#environment) | Name of an environment to which the job deploys. Also available: `environment:name`, `environment:url`, `environment:on_stop`, `environment:auto_stop_in`, and `environment:action`. | | [`except`](#onlyexcept-basic) | Limit when jobs are not created. Also available: [`except:refs`, `except:kubernetes`, `except:variables`, and `except:changes`](#onlyexcept-advanced). | | [`extends`](#extends) | Configuration entries that this job inherits from. | | [`image`](#image) | Use Docker images. Also available: `image:name` and `image:entrypoint`. | @@ -184,7 +181,7 @@ To enable or disable the inheritance of all `variables:` or `default:` parameter - `variables: true` or `variables: false` To inherit only a subset of `default:` parameters or `variables:`, specify what -you wish to inherit, and any not listed will **not** be inherited. Use +you wish to inherit. Anything not listed is **not** inherited. Use one of the following formats: ```yaml @@ -208,16 +205,16 @@ inherit: In the example below: - `rubocop`: - - **will** inherit: Nothing. + - inherits: Nothing. - `rspec`: - - **will** inherit: the default `image` and the `WEBHOOK_URL` variable. - - will **not** inherit: the default `before_script` and the `DOMAIN` variable. + - inherits: the default `image` and the `WEBHOOK_URL` variable. + - does **not** inherit: the default `before_script` and the `DOMAIN` variable. - `capybara`: - - **will** inherit: the default `before_script` and `image`. - - will **not** inherit: the `DOMAIN` and `WEBHOOK_URL` variables. + - inherits: the default `before_script` and `image`. + - does **not** inherit: the `DOMAIN` and `WEBHOOK_URL` variables. - `karma`: - - **will** inherit: the default `image` and `before_script`, and the `DOMAIN` variable. - - will **not** inherit: `WEBHOOK_URL` variable. + - inherits: the default `image` and `before_script`, and the `DOMAIN` variable. + - does **not** inherit: `WEBHOOK_URL` variable. ```yaml default: @@ -347,23 +344,23 @@ workflow: This example never allows pipelines for schedules or `push` (branches and tags) pipelines, but does allow pipelines in **all** other cases, *including* merge request pipelines. -As with `rules` defined in jobs, be careful not to use a configuration that allows -merge request pipelines and branch pipelines to run at the same time, or you could -have [duplicate pipelines](#prevent-duplicate-pipelines). +Be careful not to use a configuration that might run +merge request pipelines and branch pipelines at the same time. As with `rules` defined in jobs, +it can cause [duplicate pipelines](#prevent-duplicate-pipelines). #### `workflow:rules` templates > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/217732) in GitLab 13.0. -We provide pre-made templates for use with your pipelines that set up `workflow: rules` -for common scenarios. Usage of these will make things easier and prevent duplicate pipelines from running. +We provide templates that set up `workflow: rules` +for common scenarios. These templates help prevent duplicate pipelines. The [`Branch-Pipelines` template](https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/ci/templates/Workflows/Branch-Pipelines.gitlab-ci.yml) makes your pipelines run for branches and tags. -Branch pipeline status will be displayed within merge requests that use that branch -as a source, but this pipeline type does not support any features offered by -[Merge Request Pipelines](../merge_request_pipelines/) like +Branch pipeline status is displayed within merge requests that use the branch +as a source. However, this pipeline type does not support any features offered by +[Merge Request Pipelines](../merge_request_pipelines/), like [Pipelines for Merge Results](../merge_request_pipelines/#pipelines-for-merged-results) or [Merge Trains](../merge_request_pipelines/pipelines_for_merged_results/merge_trains/). Use this template if you are intentionally avoiding those features. @@ -391,7 +388,7 @@ include: ### `include` > - Introduced in [GitLab Premium](https://about.gitlab.com/pricing/) 10.5. -> - Available for Starter, Premium and Ultimate since 10.6. +> - Available for Starter, Premium, and Ultimate in GitLab 10.6 and later. > - [Moved](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/42861) to GitLab Core in 11.4. Using the `include` keyword allows the inclusion of external YAML files. This helps @@ -402,6 +399,10 @@ configuration files. This helps avoid duplicated configuration, for example, glo `include` requires the external YAML file to have the extensions `.yml` or `.yaml`, otherwise the external file is not included. +Using [YAML anchors](#anchors) across different YAML files sourced by `include` is not +supported. You must only refer to anchors in the same file. Instead +of using YAML anchors, you can use the [`extends` keyword](#extends). + `include` supports the following inclusion methods: | Method | Description | @@ -413,7 +414,6 @@ otherwise the external file is not included. The `include` methods do not support [variable expansion](../variables/where_variables_can_be_used.md#variables-usage). -NOTE: **Note:** `.gitlab-ci.yml` configuration included by all methods is evaluated at pipeline creation. The configuration is a snapshot in time and persisted in the database. Any changes to referenced `.gitlab-ci.yml` configuration is not reflected in GitLab until the next pipeline is created. @@ -428,11 +428,6 @@ TIP: **Tip:** Use merging to customize and override included CI/CD configurations with local definitions. Local definitions in `.gitlab-ci.yml` override included definitions. -NOTE: **Note:** -Using [YAML anchors](#anchors) across different YAML files sourced by `include` is not -supported. You must only refer to anchors in the same file. Instead -of using YAML anchors, you can use the [`extends` keyword](#extends). - #### `include:local` `include:local` includes a file from the same repository as `.gitlab-ci.yml`. @@ -442,12 +437,11 @@ You can only use files that are tracked by Git on the same branch your configuration file is on. In other words, when using a `include:local`, make sure that both `.gitlab-ci.yml` and the local file are on the same branch. +Including local files through Git submodules paths is not supported. + All [nested includes](#nested-includes) are executed in the scope of the same project, so it's possible to use local, project, remote, or template includes. -NOTE: **Note:** -Including local files through Git submodules paths is not supported. - Example: ```yaml @@ -455,7 +449,6 @@ include: - local: '/templates/.gitlab-ci-template.yml' ``` -TIP: **Tip:** Local includes can be used as a replacement for symbolic links that are not followed. This can be defined as a short local include: @@ -495,8 +488,8 @@ include: file: '/templates/.gitlab-ci-template.yml' ``` -All [nested includes](#nested-includes) are executed in the scope of the target project, -so it's possible to use local (relative to target project), project, remote +All [nested includes](#nested-includes) are executed in the scope of the target project. +This means you can use local (relative to target project), project, remote, or template includes. #### `include:remote` @@ -548,7 +541,7 @@ Nested includes allow you to compose a set of includes. A total of 100 includes is allowed, but duplicate includes are considered a configuration error. -Since [GitLab 12.4](https://gitlab.com/gitlab-org/gitlab/-/issues/28212), the time limit +In [GitLab 12.4](https://gitlab.com/gitlab-org/gitlab/-/issues/28212) and later, the time limit for resolving all files is 30 seconds. #### Additional `includes` examples @@ -635,10 +628,9 @@ job: - bundle exec rspec ``` -NOTE: **Note:** Sometimes, `script` commands must be wrapped in single or double quotes. -For example, commands that contain a colon (`:`) must be wrapped in quotes so -that the YAML parser knows to interpret the whole thing as a string rather than +For example, commands that contain a colon (`:`) must be wrapped in quotes. +The YAML parser needs to interpret the text as a string rather than a "key: value" pair. Be careful when using special characters: `:`, `{`, `}`, `[`, `]`, `,`, `&`, `*`, `#`, `?`, `|`, `-`, `<`, `>`, `=`, `!`, `%`, `@`, `` ` ``. @@ -657,15 +649,18 @@ job: > Introduced in GitLab 8.7 and requires GitLab Runner v1.2. -`before_script` is used to define a command that should be run before each +`before_script` is used to define commands that should be run before each job, including deploy jobs, but after the restoration of any [artifacts](#artifacts). This must be an array. Scripts specified in `before_script` are concatenated with any scripts specified in the main [`script`](#script), and executed together in a single shell. -`after_script` is used to define the command that runs after each -job, including failed ones. This must be an array. +`after_script` is used to define commands that run after each +job, including failed jobs. This must be an array. If a job times out or is cancelled, +the `after_script` commands are not executed. Support for executing `after_script` +commands for timed-out or cancelled jobs +[is planned](https://gitlab.com/gitlab-org/gitlab/-/issues/15603). Scripts specified in `after_script` are executed in a new shell, separate from any `before_script` or `script` scripts. As a result, they: @@ -744,11 +739,11 @@ using [`|` (literal) and `>` (folded) YAML multi-line block scalar indicators](h CAUTION: **Warning:** If multiple commands are combined into one command string, only the last command's -failure or success is reported, -[incorrectly ignoring failures from earlier commands due to a bug](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/25394). -If the success of the job depends on the success or failure of these commands, -you can run the commands as separate `script:` items, or add `exit 1` commands -as appropriate to the command string where needed. +failure or success is reported. +[Failures from earlier commands are ignored due to a bug](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/25394). +To work around this, +run each command as a separate `script:` item, or add an `exit 1` command +to each command string. You can use the `|` (literal) YAML multiline block scalar indicator to write commands over multiple lines in the `script` section of a job description. @@ -808,7 +803,7 @@ Second command line. ``` When you omit the `>` or `|` block scalar indicators, GitLab forms the command -by concatenating non-empty lines, so make sure the lines can run when concatenated. +by concatenating non-empty lines. Make sure the lines can run when concatenated. Shell [here documents](https://en.wikipedia.org/wiki/Here_document) work with the `|` and `>` operators as well. The example below transliterates the lower case letters @@ -895,6 +890,8 @@ The following stages are available to every pipeline: User-defined stages are executed after `.pre` and before `.post`. +A pipeline is not created if all jobs are in `.pre` or `.post` stages. + The order of `.pre` and `.post` can't be changed, even if defined out of order in `.gitlab-ci.yml`. For example, the following are equivalent configuration: @@ -926,9 +923,6 @@ For example, the following are equivalent configuration: - b ``` -NOTE: **Note:** -A pipeline is not created if all jobs are in `.pre` or `.post` stages. - ### `extends` > Introduced in GitLab 11.3. @@ -961,7 +955,7 @@ GitLab performs a reverse deep merge based on the keys. GitLab: - Merges the `rspec` contents into `.tests` recursively. - Doesn't merge the values of the keys. -The result is this `rspec` job: +The result is this `rspec` job, where `script: rake test` is overwritten by `script: rake rspec`: ```yaml rspec: @@ -974,9 +968,6 @@ rspec: - $RSPEC ``` -NOTE: **Note:** -Note that `script: rake test` has been overwritten by `script: rake rspec`. - If you do want to include the `rake test`, see [`before_script` and `after_script`](#before_script-and-after_script). `.tests` in this example is a [hidden job](#hide-jobs), but it's @@ -1113,7 +1104,6 @@ is either included or excluded from the pipeline, depending on the configuration If included, the job also has [certain attributes](#rules-attributes) added to it. -CAUTION: **Caution:** `rules` replaces [`only/except`](#onlyexcept-basic) and can't be used in conjunction with it. If you attempt to use both keywords in the same job, the linter returns a `key may not be used with rules` error. @@ -1500,9 +1490,8 @@ job: - spec/**.rb ``` -NOTE: **Note:** -For performance reasons, using `exists` with patterns is limited to 10000 -checks. After the 10000th check, rules with patterned globs always match. +For performance reasons, using `exists` with patterns is limited to 10,000 +checks. After the 10,000th check, rules with patterned globs always match. #### `rules:allow_failure` @@ -1543,15 +1532,15 @@ docker build: script: docker build -t my-image:$CI_COMMIT_REF_SLUG . rules: - if: '$VAR == "string value"' - changes: # Will include the job and set to when:manual if any of the follow paths match a modified file. + changes: # Include the job and set to when:manual if any of the follow paths match a modified file. - Dockerfile - docker/scripts/* when: manual - # - when: never would be redundant here, this is implied any time rules are listed. + # - when: never would be redundant here, this is implied any time rules are listed. ``` -Keywords such as `branches` or `refs` that are currently available for -`only`/`except` are not yet available in `rules` as they are being individually +Keywords such as `branches` or `refs` that are available for +`only`/`except` are not available in `rules`. They are being individually considered for their usage and behavior in this context. Future keyword improvements are being discussed in our [epic for improving `rules`](https://gitlab.com/groups/gitlab-org/-/epics/2783), where anyone can add suggestions or requests. @@ -1567,10 +1556,9 @@ job1: if: ($CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "develop") && $MY_VARIABLE ``` -NOTE: **Note:** -In GitLab 13.2 and older, the order of operations when mixing `||` and `&&` in a single rule may not have executed -in the expected order. This is [fixed](https://gitlab.com/gitlab-org/gitlab/-/issues/230938) -in GitLab 13.3. +CAUTION: **Caution:** +[Before GitLab 13.3](https://gitlab.com/gitlab-org/gitlab/-/issues/230938), +rules that use both `||` and `&&` may evaluate with an unexpected order of operations. ### `only`/`except` (basic) @@ -1611,8 +1599,8 @@ In addition, `only` and `except` allow the use of special keywords: | `triggers` | For pipelines created by using a [trigger token](../triggers/README.md#trigger-token). | | `web` | For pipelines created by using **Run pipeline** button in the GitLab UI, from the project's **CI/CD > Pipelines** section. | -In the example below, `job` will run only for refs that start with `issue-`, -whereas all branches will be skipped: +In the example below, `job` runs only for refs that start with `issue-`, +whereas all branches are skipped: ```yaml job: @@ -1637,8 +1625,8 @@ job: - branches ``` -In this example, `job` will run only for refs that are tagged, or if a build is -explicitly requested via an API trigger or a [Pipeline Schedule](../pipelines/schedules.md): +In this example, `job` runs only for refs that are tagged, or if a build is +explicitly requested by an API trigger or a [Pipeline Schedule](../pipelines/schedules.md): ```yaml job: @@ -1684,19 +1672,19 @@ job: #### Regular expressions -Because `@` is used to denote the beginning of a ref's repository path, -matching a ref name containing the `@` character in a regular expression -requires the use of the hex character code match `\x40`. +The `@` symbol denotes the beginning of a ref's repository path. +To match a ref name that contains the `@` character in a regular expression, +you must use the hex character code match `\x40`. Only the tag or branch name can be matched by a regular expression. The repository path, if given, is always matched literally. -If a regular expression shall be used to match the tag or branch name, -the entire ref name part of the pattern has to be a regular expression, -and must be surrounded by `/`. -(With regular expression flags appended after the closing `/`.) -So `issue-/.*/` won't work to match all tag names or branch names -that begin with `issue-`. +To match the tag or branch name, +the entire ref name part of the pattern must be a regular expression surrounded by `/`. +For example, you can't use `issue-/.*/` to match all tag names or branch names +that begin with `issue-`, but you can use `/issue-.*/`. + +Regular expression flags must be appended after the closing `/`. TIP: **Tip:** Use anchors `^` and `$` to avoid the regular expression @@ -1706,20 +1694,17 @@ while just `/issue/` would also match a branch called `severe-issues`. #### Supported `only`/`except` regexp syntax -CAUTION: **Warning:** -This is a breaking change that was introduced with GitLab 11.9.4. - -In GitLab 11.9.4, GitLab begun internally converting regexp used +In GitLab 11.9.4, GitLab began internally converting the regexp used in `only` and `except` parameters to [RE2](https://github.com/google/re2/wiki/Syntax). -This means that only subset of features provided by [Ruby Regexp](https://ruby-doc.org/core/Regexp.html) -is supported. [RE2](https://github.com/google/re2/wiki/Syntax) limits the set of features -provided due to computational complexity, which means some features became unavailable in GitLab 11.9.4. -For example, negative lookaheads. +[RE2](https://github.com/google/re2/wiki/Syntax) limits the set of available features +due to computational complexity, and some features, like negative lookaheads, became unavailable. +Only a subset of features provided by [Ruby Regexp](https://ruby-doc.org/core/Regexp.html) +are now supported. -For GitLab versions from 11.9.7 and up to GitLab 12.0, GitLab provides a feature flag that can be -enabled by administrators that allows users to use unsafe regexp syntax. This brings compatibility -with previously allowed syntax version and allows users to gracefully migrate to the new syntax. +From GitLab 11.9.7 to GitLab 12.0, GitLab provided a feature flag to +let you use the unsafe regexp syntax. This flag allowed +compatibility with the previous syntax version so you could gracefully migrate to the new syntax. ```ruby Feature.enable(:allow_unsafe_ruby_regexp) @@ -1727,10 +1712,6 @@ Feature.enable(:allow_unsafe_ruby_regexp) ### `only`/`except` (advanced) -CAUTION: **Warning:** -This is an _alpha_ feature, and is subject to change at any time without -prior notice! - GitLab supports both simple and complex strategies, so it's possible to use an array and a hash configuration scheme. @@ -1741,7 +1722,7 @@ Four keys are available: - `changes` - `kubernetes` -If you use multiple keys under `only` or `except`, the keys will be evaluated as a +If you use multiple keys under `only` or `except`, the keys are evaluated as a single conjoined expression. That is: - `only:` includes the job if **all** of the keys have at least one condition that matches. @@ -1752,9 +1733,9 @@ the pipeline if the following is true: - `(any listed refs are true) AND (any listed variables are true) AND (any listed changes are true) AND (any chosen Kubernetes status matches)` -In the example below, the `test` job will `only` be created when **all** of the following are true: +In the example below, the `test` job is `only` created when **all** of the following are true: -- The pipeline has been [scheduled](../../user/project/pipelines/schedules.md) **or** runs for `master`. +- The pipeline has been [scheduled](../pipelines/schedules.md) **or** runs for `master`. - The `variables` keyword matches. - The `kubernetes` service is active on the project. @@ -1775,7 +1756,7 @@ added if the following is true: - `(any listed refs are true) OR (any listed variables are true) OR (any listed changes are true) OR (a chosen Kubernetes status matches)` -In the example below, the `test` job will **not** be created when **any** of the following are true: +In the example below, the `test` job is **not** created when **any** of the following are true: - The pipeline runs for the `master` branch. - There are changes to the `README.md` file in the root directory of the repository. @@ -1797,8 +1778,8 @@ test: The `refs` strategy can take the same values as the [simplified only/except configuration](#onlyexcept-basic). -In the example below, the `deploy` job is going to be created only when the -pipeline has been [scheduled](../pipelines/schedules.md) or runs for the `master` branch: +In the example below, the `deploy` job is created only when the +pipeline is [scheduled](../pipelines/schedules.md) or runs for the `master` branch: ```yaml deploy: @@ -1814,7 +1795,7 @@ deploy: The `kubernetes` strategy accepts only the `active` keyword. -In the example below, the `deploy` job is going to be created only when the +In the example below, the `deploy` job is created only when the Kubernetes service is active in the project: ```yaml @@ -1827,12 +1808,11 @@ deploy: > `variables` policy introduced in GitLab 10.7. -The `variables` keyword is used to define variables expressions. In other words, -you can use predefined variables / project / group or -environment-scoped variables to define an expression GitLab is going to -evaluate in order to decide whether a job should be created or not. +The `variables` keyword defines variable expressions. + +These expressions determine whether or not a job should be created. -Examples of using variables expressions: +Examples of using variable expressions: ```yaml deploy: @@ -1902,22 +1882,21 @@ docker build: - more_scripts/*.{rb,py,sh} ``` -In the scenario above, when pushing commits to an existing branch in GitLab, -it creates and triggers the `docker build` job, provided that one of the -commits contains changes to any of the following: +When you push commits to an existing branch, +the `docker build` job is created, but only if changes were made to any of the following: - The `Dockerfile` file. -- Any of the files inside `docker/scripts/` directory. -- Any of the files and subdirectories inside the `dockerfiles` directory. -- Any of the files with `rb`, `py`, `sh` extensions inside the `more_scripts` directory. +- Any of the files in the `docker/scripts/` directory. +- Any of the files and subdirectories in the `dockerfiles` directory. +- Any of the files with `rb`, `py`, `sh` extensions in the `more_scripts` directory. CAUTION: **Warning:** -If using `only:changes` with [only allow merge requests to be merged if the pipeline succeeds](../../user/project/merge_requests/merge_when_pipeline_succeeds.md#only-allow-merge-requests-to-be-merged-if-the-pipeline-succeeds), -undesired behavior could result if you don't [also use `only:merge_requests`](#using-onlychanges-with-pipelines-for-merge-requests). +If you use `only:changes` with [only allow merge requests to be merged if the pipeline succeeds](../../user/project/merge_requests/merge_when_pipeline_succeeds.md#only-allow-merge-requests-to-be-merged-if-the-pipeline-succeeds), +you should [also use `only:merge_requests`](#using-onlychanges-with-pipelines-for-merge-requests). Otherwise it may not work as expected. You can also use glob patterns to match multiple files in either the root directory -of the repository, or in _any_ directory within the repository, but they must be wrapped -in double quotes or GitLab will fail to parse the `.gitlab-ci.yml`. For example: +of the repository, or in _any_ directory within the repository. However, they must be wrapped +in double quotes or GitLab can't parse them. For example: ```yaml test: @@ -1930,10 +1909,8 @@ test: - "**/*.sql" ``` -The following example will skip the `build` job if a change is detected in any file -in the root directory of the repository with a `.md` extension. This mean that if you change multiple files, -but only one file is a `.md` file, the `build` job will still be skipped and will -not run for the other files. +You can skip a job if a change is detected in any file with a +`.md` extension in the root directory of the repository: ```yaml build: @@ -1943,13 +1920,13 @@ build: - "*.md" ``` -CAUTION: **Warning:** -There are some points to be aware of when -[using this feature with new branches or tags *without* pipelines for merge requests](#using-onlychanges-without-pipelines-for-merge-requests). +If you change multiple files, but only one file ends in `.md`, +the `build` job is still skipped. The job does not run for any of the files. -CAUTION: **Warning:** -There are some points to be aware of when -[using this feature with scheduled pipelines](#using-onlychanges-with-scheduled-pipelines). +Read more about how to use this feature with: + +- [New branches or tags *without* pipelines for merge requests](#using-onlychanges-without-pipelines-for-merge-requests). +- [Scheduled pipelines](#using-onlychanges-with-scheduled-pipelines). ##### Using `only:changes` with pipelines for merge requests @@ -1957,7 +1934,7 @@ With [pipelines for merge requests](../merge_request_pipelines/index.md), it's possible to define a job to be created based on files modified in a merge request. -In order to deduce the correct base SHA of the source branch, we recommend combining +To deduce the correct base SHA of the source branch, we recommend combining this keyword with `only: [merge_requests]`. This way, file differences are correctly calculated from any further commits, thus all changes in the merge requests are properly tested in pipelines. @@ -1975,13 +1952,9 @@ docker build service one: - service-one/**/* ``` -In the scenario above, if a merge request is created or updated that changes -either files in `service-one` directory or the `Dockerfile`, GitLab creates -and triggers the `docker build service one` job. - -Note that if [pipelines for merge requests](../merge_request_pipelines/index.md) is -combined with `only: [change]`, but `only: [merge_requests]` is omitted, there could be -unwanted behavior. +In this scenario, if a merge request changes +files in the `service-one` directory or the `Dockerfile`, GitLab creates +the `docker build service one` job. For example: @@ -1994,15 +1967,17 @@ docker build service one: - service-one/**/* ``` -In the example above, a pipeline could fail due to changes to a file in `service-one/**/*`. -A later commit could then be pushed that does not include any changes to this file, -but includes changes to the `Dockerfile`, and this pipeline could pass because it's only -testing the changes to the `Dockerfile`. GitLab checks the **most recent pipeline**, -that **passed**, and will show the merge request as mergeable, despite the earlier -failed pipeline caused by a change that was not yet corrected. +In the example above, the pipeline might fail because of changes to a file in `service-one/**/*`. + +A later commit that doesn't have changes in `service-one/**/*` +but does have changes to the `Dockerfile` can pass. The job +only tests the changes to the `Dockerfile`. -With this configuration, care must be taken to check that the most recent pipeline -properly corrected any failures from previous pipelines. +GitLab checks the **most recent pipeline** that **passed**. If the merge request is mergeable, +it doesn't matter that an earlier pipeline failed because of a change that has not been corrected. + +When you use this configuration, ensure that the most recent pipeline +properly corrects any failures from previous pipelines. ##### Using `only:changes` without pipelines for merge requests @@ -2068,15 +2043,15 @@ production: This example creates four paths of execution: -- Linter: the `lint` job will run immediately without waiting for the `build` stage to complete because it has no needs (`needs: []`). +- Linter: the `lint` job runs immediately without waiting for the `build` stage to complete because it has no needs (`needs: []`). -- Linux path: the `linux:rspec` and `linux:rubocop` jobs will be run as soon +- Linux path: the `linux:rspec` and `linux:rubocop` jobs runs as soon as the `linux:build` job finishes without waiting for `mac:build` to finish. -- macOS path: the `mac:rspec` and `mac:rubocop` jobs will be run as soon +- macOS path: the `mac:rspec` and `mac:rubocop` jobs runs as soon as the `mac:build` job finishes, without waiting for `linux:build` to finish. -- The `production` job will be executed as soon as all previous jobs +- The `production` job runs as soon as all previous jobs finish; in this case: `linux:build`, `linux:rspec`, `linux:rubocop`, `mac:build`, `mac:rspec`, `mac:rubocop`. @@ -2084,14 +2059,14 @@ This example creates four paths of execution: - If `needs:` is set to point to a job that is not instantiated because of `only/except` rules or otherwise does not exist, the - pipeline will be created with YAML error. + pipeline is not created and a YAML error is shown. - The maximum number of jobs that a single job can need in the `needs:` array is limited: - For GitLab.com, the limit is 50. For more information, see our [infrastructure issue](https://gitlab.com/gitlab-com/gl-infra/infrastructure/-/issues/7541). - For self-managed instances, the limit is: 50. This limit [can be changed](#changing-the-needs-job-limit). - If `needs:` refers to a job that is marked as `parallel:`. - the current job will depend on all parallel jobs created. -- `needs:` is similar to `dependencies:` in that it needs to use jobs from prior stages, + the current job depends on all parallel jobs being created. +- `needs:` is similar to `dependencies:` in that it must use jobs from prior stages, meaning it's impossible to create circular dependencies. Depending on jobs in the current stage is not possible either, but support [is planned](https://gitlab.com/gitlab-org/gitlab/-/issues/30632). - Related to the above, stages must be explicitly defined for all jobs @@ -2108,8 +2083,7 @@ can choose a custom limit. For example, to set the limit to 100: Plan.default.actual_limits.update!(ci_needs_size_limit: 100) ``` -NOTE: **Note:** -To disable the ability to use DAG, set the limit to `0`. +To disable directed acyclic graphs (DAG), set the limit to `0`. #### Artifact downloads with `needs` @@ -2117,12 +2091,12 @@ To disable the ability to use DAG, set the limit to `0`. When using `needs`, artifact downloads are controlled with `artifacts: true` (default) or `artifacts: false`. -Since GitLab 12.6, you can't combine the [`dependencies`](#dependencies) keyword +In GitLab 12.6 and later, you can't combine the [`dependencies`](#dependencies) keyword with `needs` to control artifact downloads in jobs. `dependencies` is still valid in jobs that do not use `needs`. -In the example below, the `rspec` job will download the `build_job` artifacts, while the -`rubocop` job won't: +In the example below, the `rspec` job downloads the `build_job` artifacts, while the +`rubocop` job doesn't: ```yaml build_job: @@ -2144,9 +2118,9 @@ rubocop: artifacts: false ``` -Additionally, in the three syntax examples below, the `rspec` job will download the artifacts -from all three `build_jobs`, as `artifacts` is true for `build_job_1`, and will -**default** to true for both `build_job_2` and `build_job_3`. +Additionally, in the three syntax examples below, the `rspec` job downloads the artifacts +from all three `build_jobs`. `artifacts` is true for `build_job_1` and +**defaults** to true for both `build_job_2` and `build_job_3`. ```yaml rspec: @@ -2161,9 +2135,10 @@ rspec: > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/14311) in GitLab v12.7. -`needs` can be used to download artifacts from up to five jobs in pipelines on -[other refs in the same project](#artifact-downloads-between-pipelines-in-the-same-project), -or pipelines in different projects, groups and namespaces: +Use `needs` to download artifacts from up to five jobs in pipelines: + +- [On other refs in the same project](#artifact-downloads-between-pipelines-in-the-same-project). +- In different projects, groups and namespaces. ```yaml build_job: @@ -2177,7 +2152,7 @@ build_job: artifacts: true ``` -`build_job` will download the artifacts from the latest successful `build-1` job +`build_job` downloads the artifacts from the latest successful `build-1` job on the `master` branch in the `group/project-name` project. If the project is in the same group or namespace, you can omit them from the `project:` key. For example, `project: group/project-name` or `project: project-name`. @@ -2186,9 +2161,10 @@ The user running the pipeline must have at least `reporter` access to the group ##### Artifact downloads between pipelines in the same project -`needs` can be used to download artifacts from different pipelines in the current project -by setting the `project` keyword as the current project's name, and specifying a ref. -In the example below, `build_job` will download the artifacts for the latest successful +Use `needs` to download artifacts from different pipelines in the current project. +Set the `project` keyword as the current project's name, and specify a ref. + +In this example, `build_job` downloads the artifacts for the latest successful `build-1` job with the `other-ref` ref: ```yaml @@ -2220,7 +2196,6 @@ build_job: artifacts: true ``` -NOTE: **Note:** Downloading artifacts from jobs that are run in [`parallel:`](#parallel) is not supported. ### `tags` @@ -2232,7 +2207,7 @@ When you register a runner, you can specify the runner's tags, for example `ruby`, `postgres`, `development`. In this example, the job is run by a runner that -has both `ruby` AND `postgres` tags defined. +has both `ruby` and `postgres` tags defined. ```yaml job: @@ -2271,16 +2246,16 @@ The default value is `false`, except for [manual](#whenmanual) jobs using the `when: manual` syntax, unless using [`rules:`](#rules) syntax, where all jobs default to false, *including* `when: manual` jobs. -When enabled and the job fails, the job will show an orange warning in the UI. -However, the logical flow of the pipeline will consider the job a +When `allow_failure` is enabled and the job fails, the job shows an orange warning in the UI. +However, the logical flow of the pipeline considers the job a success/passed, and is not blocked. -Assuming all other jobs are successful, the job's stage and its pipeline will -show the same orange warning. However, the associated commit will be marked +Assuming all other jobs are successful, the job's stage and its pipeline +show the same orange warning. However, the associated commit is marked as "passed", without warnings. -In the example below, `job1` and `job2` will run in parallel, but if `job1` -fails, it won't stop the next stage from running, since it's marked with +In the example below, `job1` and `job2` run in parallel, but if `job1` +fails, it doesn't stop the next stage from running, because it's marked with `allow_failure: true`: ```yaml @@ -2309,15 +2284,15 @@ failure. `when` can be set to one of the following values: 1. `on_success` - execute job only when all jobs from prior stages - succeed (or are considered succeeding because they are marked - `allow_failure`). This is the default. + succeed (or are considered succeeding because they have `allow_failure: true`). + This is the default. 1. `on_failure` - execute job only when at least one job from prior stages fails. 1. `always` - execute job regardless of the status of jobs from prior stages. 1. `manual` - execute job manually (added in GitLab 8.10). Read about - [manual actions](#whenmanual) below. + [manual jobs](#whenmanual) below. 1. `delayed` - execute job after a certain period (added in GitLab 11.14). - Read about [delayed actions](#whendelayed) below. + Read about [delayed jobs](#whendelayed) below. 1. `never`: - With [`rules`](#rules), don't execute job. - With [`workflow:rules`](#workflowrules), don't run pipeline. @@ -2371,45 +2346,44 @@ The above script: #### `when:manual` > - Introduced in GitLab 8.10. -> - Blocking manual actions were introduced in GitLab 9.0. +> - Blocking manual jobs were introduced in GitLab 9.0. > - Protected actions were introduced in GitLab 9.2. -Manual actions are a special type of job that are not executed automatically, -they need to be explicitly started by a user. An example usage of manual actions -would be a deployment to a production environment. Manual actions can be started -from the pipeline, job, environment, and deployment views. Read more at the -[environments documentation](../environments/index.md#configuring-manual-deployments). +A manual job is a type of job that is not executed automatically and must be explicitly +started by a user. You might want to use manual jobs for things like deploying to production. -Manual actions can be either optional or blocking. Blocking manual actions will -block the execution of the pipeline at the stage this action is defined in. It's -possible to resume execution of the pipeline when someone executes a blocking -manual action by clicking a _play_ button. +To make a job manual, add `when: manual` to its configuration. -When a pipeline is blocked, it won't be merged if Merge When Pipeline Succeeds -is set. Blocked pipelines also do have a special status, called _manual_. -When the `when:manual` syntax is used, manual actions are non-blocking by -default. If you want to make manual action blocking, it's necessary to add -`allow_failure: false` to the job's definition in `.gitlab-ci.yml`. +Manual jobs can be started from the pipeline, job, [environment](../environments/index.md#configuring-manual-deployments), +and deployment views. -Optional manual actions have `allow_failure: true` set by default and their -Statuses don't contribute to the overall pipeline status. So, if a manual -action fails, the pipeline will eventually succeed. +Manual jobs can be either optional or blocking: -NOTE: **Note:** -When using [`rules:`](#rules), `allow_failure` defaults to `false`, including for manual jobs. +- **Optional**: Manual jobs have [`allow_failure: true](#allow_failure) set by default + and are considered optional. The status of an optional manual job does not contribute + to the overall pipeline status. A pipeline can succeed even if all its manual jobs fail. -Manual actions are considered to be write actions, so permissions for -[protected branches](../../user/project/protected_branches.md) are used when -a user wants to trigger an action. In other words, in order to trigger a manual -action assigned to a branch that the pipeline is running for, the user needs to -have the ability to merge to this branch. It's possible to use protected environments -to more strictly [protect manual deployments](#protecting-manual-jobs) from being -run by unauthorized users. +- **Blocking**: To make a blocking manual job, add `allow_failure: false` to its configuration. + Blocking manual jobs stop further execution of the pipeline at the stage where the + job is defined. To let the pipeline continue running, click **{play}** (play) on + the blocking manual job. -NOTE: **Note:** -Using `when:manual` and `trigger` together results in the error `jobs:#{job-name} when -should be on_success, on_failure or always`, because `when:manual` prevents triggers -being used. + Merge requests in projects with [merge when pipeline succeeds](../../user/project/merge_requests/merge_when_pipeline_succeeds.md) + enabled can't be merged with a blocked pipeline. Blocked pipelines show a status + of **blocked**. + +When you use [`rules:`](#rules), `allow_failure` defaults to `false`, including for manual jobs. + +To trigger a manual job, a user must have permission to merge to the assigned branch. +You can use [protected branches](../../user/project/protected_branches.md) to more strictly +[protect manual deployments](#protecting-manual-jobs) from being run by unauthorized users. + +In [GitLab 13.5](https://gitlab.com/gitlab-org/gitlab/-/issues/201938) and later, you +can use `when:manual` in the same job as [`trigger`](#trigger). In GitLab 13.4 and +earlier, using them together causes the error `jobs:#{job-name} when should be on_success, on_failure or always`. +It is deployed behind the `:ci_manual_bridges` [feature flag](../../user/feature_flags.md), which is **enabled by default**. +[GitLab administrators with access to the Rails console](../../administration/feature_flags.md) +can opt to disable it. ##### Protecting manual jobs **(PREMIUM)** @@ -2441,12 +2415,12 @@ To do this, you must: 1. In the [protected environments settings](../environments/protected_environments.md#protecting-environments), select the environment (`production` in the example above) and add the users, roles or groups that are authorized to trigger the manual job to the **Allowed to Deploy** list. Only those in - this list will be able to trigger this manual job, as well as GitLab administrators + this list can trigger this manual job, as well as GitLab administrators who are always able to use protected environments. -Additionally, if a manual job is defined as blocking by adding `allow_failure: false`, -the next stages of the pipeline won't run until the manual job is triggered. This -can be used as a way to have a defined list of users allowed to "approve" later pipeline +Additionally, if you define a manual job as blocking by adding `allow_failure: false`, +the pipeline's next stages don't run until the manual job is triggered. You can use this +to define a list of users allowed to "approve" later pipeline stages by triggering the blocking manual job. #### `when:delayed` @@ -2465,11 +2439,11 @@ provided. `start_in` key must be less than or equal to one week. Examples of val - `1 day` - `1 week` -When there is a delayed job in a stage, the pipeline won't progress until the delayed job has finished. +When there is a delayed job in a stage, the pipeline doesn't progress until the delayed job has finished. This means this keyword can also be used for inserting delays between different stages. The timer of a delayed job starts immediately after the previous stage has completed. -Similar to other types of jobs, a delayed job's timer won't start unless the previous stage passed. +Similar to other types of jobs, a delayed job's timer doesn't start unless the previous stage passed. The following example creates a job named `timed rollout 10%` that is executed 30 minutes after the previous stage has completed: @@ -2482,7 +2456,7 @@ timed rollout 10%: ``` You can stop the active timer of a delayed job by clicking the **{time-out}** (**Unschedule**) button. -This job will never be executed in the future unless you execute the job manually. +This job can no longer be scheduled to run automatically. You can, however, execute the job manually. To start a delayed job immediately, click the **Play** button. Soon GitLab Runner picks up and starts the job. @@ -2495,7 +2469,7 @@ Soon GitLab Runner picks up and starts the job. `environment` is used to define that a job deploys to a specific environment. If `environment` is specified and no environment under that name exists, a new -one will be created automatically. +one is created automatically. In its simplest form, the `environment` keyword can be defined like: @@ -2506,7 +2480,7 @@ deploy to production: environment: production ``` -In the above example, the `deploy to production` job will be marked as doing a +In the above example, the `deploy to production` job is marked as doing a deployment to the `production` environment. #### `environment:name` @@ -2574,12 +2548,12 @@ deploy to production: > - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/22191) in GitLab 8.13. > - Starting with GitLab 8.14, when you have an environment that has a stop action -> defined, GitLab will automatically trigger a stop action when the associated +> defined, GitLab automatically triggers a stop action when the associated > branch is deleted. -Closing (stopping) environments can be achieved with the `on_stop` keyword defined under -`environment`. It declares a different job that runs in order to close -the environment. +Closing (stopping) environments can be achieved with the `on_stop` keyword +defined under `environment`. It declares a different job that runs to close the +environment. Read the `environment:action` section for an example. @@ -2591,7 +2565,7 @@ The `action` keyword can be used to specify jobs that prepare, start, or stop en | **Value** | **Description** | |-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| -| start | Default value. Indicates that job starts the environment. Deployment will be created after job starts. | +| start | Default value. Indicates that job starts the environment. The deployment is created after the job starts. | | prepare | Indicates that job is only preparing the environment. Does not affect deployments. [Read more about environments](../environments/index.md#prepare-an-environment) | | stop | Indicates that job stops deployment. See the example below. | @@ -2617,21 +2591,20 @@ stop_review_app: action: stop ``` -In the above example we set up the `review_app` job to deploy to the `review` -environment, and we also defined a new `stop_review_app` job under `on_stop`. -Once the `review_app` job is successfully finished, it will trigger the -`stop_review_app` job based on what is defined under `when`. In this case we -set it up to `manual` so it will need a [manual action](#whenmanual) via -GitLab's web interface in order to run. +In the above example, the `review_app` job deploys to the `review` +environment. A new `stop_review_app` job is listed under `on_stop`. +After the `review_app` job is finished, it triggers the +`stop_review_app` job based on what is defined under `when`. In this case, +it is set to `manual`, so it needs a [manual action](#whenmanual) from +GitLab's user interface to run. -Also in the example, `GIT_STRATEGY` is set to `none` so that GitLab Runner won’t -try to check out the code after the branch is deleted when the `stop_review_app` -job is [automatically triggered](../environments/index.md#automatically-stopping-an-environment). +Also in the example, `GIT_STRATEGY` is set to `none`. If the +`stop_review_app` job is [automatically triggered](../environments/index.md#automatically-stopping-an-environment), +the runner won’t try to check out the code after the branch is deleted. -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 example also overwrites global variables. If your `stop` `environment` job depends +on global variables, you can use [anchor variables](#yaml-anchors-for-variables) when you set the `GIT_STRATEGY`. +This changes the job without overriding the global variables. The `stop_review_app` job is **required** to have the following keywords defined: @@ -2640,10 +2613,12 @@ The `stop_review_app` job is **required** to have the following keywords defined - `environment:action` Additionally, both jobs should have matching [`rules`](../yaml/README.md#onlyexcept-basic) -or [`only/except`](../yaml/README.md#onlyexcept-basic) configuration. In the example -above, if the configuration is not identical, the `stop_review_app` job might not be -included in all pipelines that include the `review_app` job, and it will not be -possible to trigger the `action: stop` to stop the environment automatically. +or [`only/except`](../yaml/README.md#onlyexcept-basic) configuration. + +In the example above, if the configuration is not identical: + +- The `stop_review_app` job might not be included in all pipelines that include the `review_app` job. +- It is not possible to trigger the `action: stop` to stop the environment automatically. #### `environment:auto_stop_in` @@ -2687,7 +2662,7 @@ deploy: namespace: production ``` -This will set up the `deploy` job to deploy to the `production` +This configuration sets up the `deploy` job to deploy to the `production` environment, using the `production` [Kubernetes namespace](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/). @@ -2719,11 +2694,11 @@ deploy as review app: url: https://$CI_ENVIRONMENT_SLUG.example.com/ ``` -The `deploy as review app` job will be marked as deployment to dynamically +The `deploy as review app` job is marked as deployment to dynamically create the `review/$CI_COMMIT_REF_NAME` environment, where `$CI_COMMIT_REF_NAME` is an [environment variable](../variables/README.md) set by the runner. The `$CI_ENVIRONMENT_SLUG` variable is based on the environment name, but suitable -for inclusion in URLs. In this case, if the `deploy as review app` job was run +for inclusion in URLs. In this case, if the `deploy as review app` job is run in a branch named `pow`, this environment would be accessible with an URL like `https://review-pow.example.com/`. @@ -2742,16 +2717,15 @@ as Review Apps. You can see a simple example using Review Apps at > by default. > - From GitLab 9.2, caches are restored before [artifacts](#artifacts). -TIP: **Learn more:** -Read how caching works and find out some good practices in the -[caching dependencies documentation](../caching/index.md). - `cache` is used to specify a list of files and directories that should be cached between jobs. You can only use paths that are within the local working copy. If `cache` is defined outside the scope of jobs, it means it's set -globally and all jobs will use that definition. +globally and all jobs use that definition. + +Read how caching works and find out some good practices in the +[caching dependencies documentation](../caching/index.md). #### `cache:paths` @@ -2777,7 +2751,7 @@ rspec: ``` Locally defined cache overrides globally defined options. The following `rspec` -job will cache only `binaries/`: +job caches only `binaries/`: ```yaml cache: @@ -2792,20 +2766,20 @@ rspec: - binaries/ ``` -Note that since cache is shared between jobs, if you're using different -paths for different jobs, you should also set a different **cache:key** -otherwise cache content can be overwritten. +The cache is shared between jobs, so if you're using different +paths for different jobs, you should also set a different `cache:key`. +Otherwise cache content can be overwritten. #### `cache:key` > Introduced in GitLab Runner v1.0.0. -Since the cache is shared between jobs, if you're using different -paths for different jobs, you should also set a different `cache:key` -otherwise cache content can be overwritten. +The cache is shared between jobs, so if you're using different +paths for different jobs, you should also set a different `cache:key`. +Otherwise cache content can be overwritten. -The `key` parameter defines the affinity of caching between jobs, -to have a single cache for all jobs, cache per-job, cache per-branch +The `key` parameter defines the affinity of caching between jobs. +You can have a single cache for all jobs, cache per-job, cache per-branch, or any other way that fits your workflow. This way, you can fine tune caching, including caching data between different jobs or even different branches. @@ -2814,10 +2788,6 @@ The `cache:key` variable can use any of the set, is just literal `default`, which means everything is shared between pipelines and jobs by default, starting from GitLab 9.0. -NOTE: **Note:** -The `cache:key` variable can't contain the `/` character, or the equivalent -URI-encoded `%2F`; a value made only of dots (`.`, `%2E`) is also forbidden. - For example, to enable per-branch caching: ```yaml @@ -2837,18 +2807,23 @@ cache: - binaries/ ``` +The `cache:key` variable can't contain the `/` character, or the equivalent +URI-encoded `%2F`. A value made only of dots (`.`, `%2E`) is also forbidden. + +You can specify a [fallback cache key](#fallback-cache-key) to use if the specified `cache:key` is not found. + ##### `cache:key:files` > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/18986) in GitLab v12.5. The `cache:key:files` keyword extends the `cache:key` functionality by making it easier -to reuse some caches, and rebuild them less often, which will speed up subsequent pipeline +to reuse some caches, and rebuild them less often, which speeds up subsequent pipeline runs. -When you include `cache:key:files`, you must also list the project files that will be used to generate the key, up to a maximum of two files. -The cache `key` will be a SHA checksum computed from the most recent commits (up to two, if two files are listed) +When you include `cache:key:files`, you must also list the project files that are used to generate the key, up to a maximum of two files. +The cache `key` is a SHA checksum computed from the most recent commits (up to two, if two files are listed) that changed the given files. If neither file was changed in any commits, -the fallback key will be `default`. +the fallback key is `default`. ```yaml cache: @@ -2864,7 +2839,7 @@ cache: In this example we're creating a cache for Ruby and Node.js dependencies that is tied to current versions of the `Gemfile.lock` and `package.json` files. Whenever one of these files changes, a new cache key is computed and a new cache is created. Any future -job runs using the same `Gemfile.lock` and `package.json` with `cache:key:files` will +job runs that use the same `Gemfile.lock` and `package.json` with `cache:key:files` use the new cache, instead of rebuilding the dependencies. ##### `cache:key:prefix` @@ -2897,11 +2872,11 @@ rspec: - bundle exec rspec ``` -For example, adding a `prefix` of `$CI_JOB_NAME` will -cause the key to look like: `rspec-feef9576d21ee9b6a32e30c5c79d0a0ceb68d1e5` and +For example, adding a `prefix` of `$CI_JOB_NAME` +causes the key to look like: `rspec-feef9576d21ee9b6a32e30c5c79d0a0ceb68d1e5` and the job cache is shared across different branches. If a branch changes -`Gemfile.lock`, that branch will have a new SHA checksum for `cache:key:files`. A new cache key -will be generated, and a new cache will be created for that key. +`Gemfile.lock`, that branch has a new SHA checksum for `cache:key:files`. A new cache key +is generated, and a new cache is created for that key. If `Gemfile.lock` is not found, the prefix is added to `default`, so the key in the example would be `rspec-default`. @@ -2928,6 +2903,28 @@ rspec: - binaries/ ``` +#### `cache:when` + +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/18969) in GitLab 13.5 and GitLab Runner v13.5.0. + +`cache:when` defines when to save the cache, based on the status of the job. You can +set `cache:when` to: + +- `on_success` - save the cache only when the job succeeds. This is the default. +- `on_failure` - save the cache only when the job fails. +- `always` - save the cache regardless of the job status. + +For example, to store a cache whether or not the job fails or succeeds: + +```yaml +rspec: + script: rspec + cache: + paths: + - rspec/ + when: 'always' +``` + #### `cache:policy` > Introduced in GitLab 9.4. @@ -2967,13 +2964,13 @@ rspec: - bundle exec rspec ... ``` -This helps to speed up job execution and reduce load on the cache server, -especially when you have a large number of cache-using jobs executing in +This helps to speed up job execution and reduce load on the cache server. +It is especially helpful when you have a large number of cache-using jobs executing in parallel. -Additionally, if you have a job that unconditionally recreates the cache without -reference to its previous contents, you can use `policy: push` in that job to -skip the download step. +If you have a job that unconditionally recreates the cache without +referring to its previous contents, you can skip the download step. +To do so, add `policy: push` to the job. ### `artifacts` @@ -2986,8 +2983,8 @@ skip the download step. `artifacts` is used to specify a list of files and directories that are attached to the job when it [succeeds, fails, or always](#artifactswhen). -The artifacts will be sent to GitLab after the job finishes and will -be available for download in the GitLab UI provided that the size is not +The artifacts are sent to GitLab after the job finishes. They are +available for download in the GitLab UI if the size is not larger than the [maximum artifact size](../../user/gitlab_com/index.md#gitlab-cicd). [Read more about artifacts](../pipelines/job_artifacts.md). @@ -3003,7 +3000,7 @@ patterns and: - In GitLab Runner 12.10 and earlier, [`filepath.Match`](https://pkg.go.dev/path/filepath/#Match). -To restrict which jobs a specific job will fetch artifacts from, see [dependencies](#dependencies). +To restrict which jobs a specific job fetches artifacts from, see [dependencies](#dependencies). Send all files in `binaries` and `.config`: @@ -3026,7 +3023,7 @@ job: You may want to create artifacts only for tagged releases to avoid filling the build server storage with temporary build artifacts. -Create artifacts only for tags (`default-job` won't create artifacts): +Create artifacts only for tags (`default-job` doesn't create artifacts): ```yaml default-job: @@ -3098,10 +3095,10 @@ test: paths: ['file.txt'] ``` -With this configuration, GitLab will add a link **artifact 1** to the relevant merge request +With this configuration, GitLab adds a link **artifact 1** to the relevant merge request that points to `file1.txt`. -An example that will match an entire directory: +An example that matches an entire directory: ```yaml test: @@ -3116,12 +3113,12 @@ Note the following: - Artifacts do not display in the merge request UI when using variables to define the `artifacts:paths`. - A maximum of 10 job artifacts per merge request can be exposed. - Glob patterns are unsupported. -- If a directory is specified, the link will be to the job [artifacts browser](../pipelines/job_artifacts.md#browsing-artifacts) if there is more than +- If a directory is specified, the link is to the job [artifacts browser](../pipelines/job_artifacts.md#browsing-artifacts) if there is more than one file in the directory. - For exposed single file artifacts with `.html`, `.htm`, `.txt`, `.json`, `.xml`, and `.log` extensions, if [GitLab Pages](../../administration/pages/index.md) is: - - Enabled, GitLab will automatically render the artifact. - - Not enabled, you will see the file in the artifacts browser. + - Enabled, GitLab automatically renders the artifact. + - Not enabled, the file is displayed in the artifacts browser. #### `artifacts:name` @@ -3133,11 +3130,6 @@ useful when you want to download the archive from GitLab. The `artifacts:name` variable can make use of any of the [predefined variables](../variables/README.md). The default name is `artifacts`, which becomes `artifacts.zip` when you download it. -NOTE: **Note:** -If your branch-name contains forward slashes -(for example `feature/my-feature`) it's advised to use `$CI_COMMIT_REF_SLUG` -instead of `$CI_COMMIT_REF_NAME` for proper naming of the artifact. - To create an archive with a name of the current job: ```yaml @@ -3159,6 +3151,10 @@ job: - binaries/ ``` +If your branch-name contains forward slashes +(for example `feature/my-feature`) it's advised to use `$CI_COMMIT_REF_SLUG` +instead of `$CI_COMMIT_REF_NAME` for proper naming of the artifact. + To create an archive with a name of the current job and the current branch or tag including only the binaries directory: @@ -3207,10 +3203,8 @@ job: #### `artifacts:untracked` `artifacts:untracked` is used to add all Git untracked files as artifacts (along -to the paths defined in `artifacts:paths`). - -NOTE: **Note:** -`artifacts:untracked` ignores configuration in the repository's `.gitignore` file. +to the paths defined in `artifacts:paths`). `artifacts:untracked` ignores configuration +in the repository's `.gitignore` file. Send all Git untracked files: @@ -3250,7 +3244,7 @@ failure. 1. `on_failure` - upload artifacts only when the job fails. 1. `always` - upload artifacts regardless of the job status. -To upload artifacts only when job fails: +For example, to upload artifacts only when a job fails: ```yaml job: @@ -3300,7 +3294,6 @@ job: expire_in: 1 week ``` -NOTE: **Note:** The latest artifacts for refs are locked against deletion, and kept regardless of the expiry time. [Introduced in](https://gitlab.com/gitlab-org/gitlab/-/issues/16267) GitLab 13.0 behind a disabled feature flag, and [made the default behavior](https://gitlab.com/gitlab-org/gitlab/-/issues/229936) @@ -3335,24 +3328,27 @@ These are the available report types: > Introduced in GitLab 8.6 and GitLab Runner v1.1.1. -By default, all [`artifacts`](#artifacts) from all previous [stages](#stages) -are passed, but you can use the `dependencies` parameter to define a limited -list of jobs (or no jobs) to fetch artifacts from. +By default, all [`artifacts`](#artifacts) from previous [stages](#stages) +are passed to each job. However, you can use the `dependencies` parameter to +define a limited list of jobs to fetch artifacts from. You can also set a job to download no artifacts at all. To use this feature, define `dependencies` in context of the job and pass a list of all previous jobs the artifacts should be downloaded from. -You can only define jobs from stages that are executed before the current one. -An error will be shown if you define jobs from the current stage or next ones. -Defining an empty array will skip downloading any artifacts for that job. -The status of the previous job is not considered when using `dependencies`, so -if it failed or it's a manual job that was not run, no error occurs. -In the following example, we define two jobs with artifacts, `build:osx` and +You can define jobs from stages that were executed before the current one. +An error occurs if you define jobs from the current or an upcoming stage. + +To prevent a job from downloading artifacts, define an empty array. + +When you use `dependencies`, the status of the previous job is not considered. +If a job fails or it's a manual job that was not run, no error occurs. + +The following example defines two jobs with artifacts: `build:osx` and `build:linux`. When the `test:osx` is executed, the artifacts from `build:osx` -will be downloaded and extracted in the context of the build. The same happens +are downloaded and extracted in the context of the build. The same happens for `test:linux` and artifacts from `build:linux`. -The job `deploy` will download artifacts from all previous jobs because of +The job `deploy` downloads artifacts from all previous jobs because of the [stage](#stages) precedence: ```yaml @@ -3387,16 +3383,15 @@ deploy: script: make deploy ``` -##### When a dependent job will fail +##### When a dependent job fails > Introduced in GitLab 10.3. If the artifacts of the job that is set as a dependency have been [expired](#artifactsexpire_in) or [erased](../pipelines/job_artifacts.md#erasing-artifacts), then -the dependent job will fail. +the dependent job fails. -NOTE: **Note:** You can ask your administrator to [flip this switch](../../administration/job_artifacts.md#validation-for-dependencies) and bring back the old behavior. @@ -3409,7 +3404,7 @@ Use `coverage` to configure how code coverage is extracted from the job output. Regular expressions are the only valid kind of value expected here. So, using -surrounding `/` is mandatory in order to consistently and explicitly represent +surrounding `/` is mandatory to consistently and explicitly represent a regular expression string. You must escape special characters if you want to match them literally. @@ -3426,17 +3421,17 @@ job1: > - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/3442) in GitLab 9.5. > - [Behavior expanded](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/3515) in GitLab 11.5 to control which failures to retry on. -Use `retry` to configure how many times a job is going to be retried in +Use `retry` to configure how many times a job is retried in case of a failure. -When a job fails and has `retry` configured, it's going to be processed again -up to the amount of times specified by the `retry` keyword. +When a job fails, the job is processed again, +until the limit specified by the `retry` keyword is reached. -If `retry` is set to 2, and a job succeeds in a second run (first retry), it won't be retried -again. `retry` value has to be a positive integer, equal or larger than 0, but -lower or equal to 2 (two retries maximum, three runs in total). +If `retry` is set to `2`, and a job succeeds in a second run (first retry), it is not retried. +The `retry` value must be a positive integer, from `0` to `2` +(two retries maximum, three runs in total). -A simple example to retry in all failure cases: +This example retries all failure cases: ```yaml test: @@ -3444,7 +3439,7 @@ test: retry: 2 ``` -By default, a job will be retried on all failure cases. To have a better control +By default, a job is retried on all failure cases. To have better control over which failures to retry, `retry` can be a hash with the following keys: - `max`: The maximum number of retries. @@ -3460,8 +3455,8 @@ test: when: runner_system_failure ``` -If there is another failure, other than a runner system failure, the job will -not be retried. +If there is another failure, other than a runner system failure, the job +is not retried. To retry on multiple failure cases, `when` can also be an array of failures: @@ -3478,10 +3473,10 @@ test: Possible values for `when` are: <!-- - Please make sure to update `RETRY_WHEN_IN_DOCUMENTATION` array in - `spec/lib/gitlab/ci/config/entry/retry_spec.rb` if you change any of - the documented values below. The test there makes sure that all documented - values are really valid as a configuration option and therefore should always + If you change any of the values below, make sure to update the `RETRY_WHEN_IN_DOCUMENTATION` + array in `spec/lib/gitlab/ci/config/entry/retry_spec.rb`. + The test there makes sure that all documented + values are valid as a configuration option and therefore should always stay in sync with this documentation. --> @@ -3543,7 +3538,6 @@ test: parallel: 5 ``` -TIP: **Tip:** Parallelize tests suites across parallel jobs. Different languages have different tools to facilitate this. @@ -3578,6 +3572,12 @@ job split into three separate jobs. Use `matrix:` to configure different variables for jobs that are running in parallel. There can be from 2 to 50 jobs. +[In GitLab 13.5](https://gitlab.com/gitlab-org/gitlab/-/issues/26362) and later, +you can have one-dimensional matrices with a single job. +The ability to have one-dimensional matrices is [deployed behind a feature flag](../../user/feature_flags.md), +enabled by default. It's enabled on GitLab.com. For self-managed GitLab instances, +administrators can opt to disable it by [disabling the `one_dimensional_matrix:` feature flag](../../administration/feature_flags.md). **(CORE ONLY)** + Every job gets the same `CI_NODE_TOTAL` [environment variable](../variables/README.md#predefined-environment-variables) value, and a unique `CI_NODE_INDEX` value. ```yaml @@ -3623,19 +3623,25 @@ Job naming style [was improved](https://gitlab.com/gitlab-org/gitlab/-/issues/23 Use `trigger` to define a downstream pipeline trigger. When GitLab starts a job created with a `trigger` definition, a downstream pipeline is created. +Jobs with `trigger` can only use a [limited set of keywords](../multi_project_pipelines.md#limitations). +For example, you can't run commands with [`script`](#script), [`before_script`](#before_script-and-after_script), +or [`after_script`](#before_script-and-after_script). + You can use this keyword to create two different types of downstream pipelines: - [Multi-project pipelines](../multi_project_pipelines.md#creating-multi-project-pipelines-from-gitlab-ciyml) - [Child pipelines](../parent_child_pipelines.md) -[Since GitLab 13.2](https://gitlab.com/gitlab-org/gitlab/-/issues/197140/), you can -see which job triggered a downstream pipeline by hovering your mouse cursor over -the downstream pipeline job in the [pipeline graph](../pipelines/index.md#visualize-pipelines). +[In GitLab 13.2](https://gitlab.com/gitlab-org/gitlab/-/issues/197140/) and later, you can +view which job triggered a downstream pipeline. In the [pipeline graph](../pipelines/index.md#visualize-pipelines), +hover over the downstream pipeline job. -NOTE: **Note:** -Using a `trigger` with `when:manual` together results in the error `jobs:#{job-name} -when should be on_success, on_failure or always`, because `when:manual` prevents -triggers being used. +In [GitLab 13.5](https://gitlab.com/gitlab-org/gitlab/-/issues/201938) and later, you +can use [`when:manual`](#whenmanual) in the same job as `trigger`. In GitLab 13.4 and +earlier, using them together causes the error `jobs:#{job-name} when should be on_success, on_failure or always`. +It is deployed behind the `:ci_manual_bridges` [feature flag](../../user/feature_flags.md), which is **enabled by default**. +[GitLab administrators with access to the Rails console](../../administration/feature_flags.md) +can opt to disable it. #### Simple `trigger` syntax for multi-project pipelines @@ -3654,7 +3660,7 @@ staging: #### Complex `trigger` syntax for multi-project pipelines -It's possible to configure a branch name that GitLab will use to create +You can configure a branch name that GitLab uses to create a downstream pipeline with: ```yaml @@ -3669,7 +3675,7 @@ staging: branch: stable ``` -It's possible to mirror the status from a triggered pipeline: +To mirror the status from a triggered pipeline: ```yaml trigger_job: @@ -3678,7 +3684,7 @@ trigger_job: strategy: depend ``` -It's possible to mirror the status from an upstream pipeline: +To mirror the status from an upstream pipeline: ```yaml upstream_bridge: @@ -3736,14 +3742,30 @@ child-pipeline: The `generated-config.yml` is extracted from the artifacts and used as the configuration for triggering the child pipeline. +##### Trigger child pipeline with files from another project + +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/205157) in GitLab 13.5. + +To trigger child pipelines with files from another private project under the same +GitLab instance, use [`include:file`](#includefile): + +```yaml +child-pipeline: + trigger: + include: + - project: 'my-group/my-pipeline-library' + ref: 'master' + file: '/path/to/child-pipeline.yml' +``` + #### Linking pipelines with `trigger:strategy` By default, the `trigger` job completes with the `success` status as soon as the downstream pipeline is created. To force the `trigger` job to wait for the downstream (multi-project or child) pipeline to complete, use -`strategy: depend`. This will make the trigger job wait with a "running" status until the triggered -pipeline completes. At that point, the `trigger` job will complete and display the same status as +`strategy: depend`. This setting makes the trigger job wait with a "running" status until the triggered +pipeline completes. At that point, the `trigger` job completes and displays the same status as the downstream job. ```yaml @@ -3753,16 +3775,16 @@ trigger_job: strategy: depend ``` -This can help keep your pipeline execution linear. In the example above, jobs from -subsequent stages will wait for the triggered pipeline to successfully complete before -starting, at the cost of reduced parallelization. +This setting can help keep your pipeline execution linear. In the example above, jobs from +subsequent stages wait for the triggered pipeline to successfully complete before +starting, which reduces parallelization. #### Trigger a pipeline by API call -Triggers can be used to force a rebuild of a specific branch, tag or commit, -with an API call when a pipeline gets created using a trigger token. +To force a rebuild of a specific branch, tag, or commit, you can use an API call +with a trigger token. -Not to be confused with the [`trigger`](#trigger) parameter. +The trigger token is different than the [`trigger`](#trigger) parameter. [Read more in the triggers documentation.](../triggers/README.md) @@ -3771,19 +3793,18 @@ Not to be confused with the [`trigger`](#trigger) parameter. > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/32022) in GitLab 12.3. `interruptible` is used to indicate that a job should be canceled if made redundant by a newer pipeline run. Defaults to `false`. -This value will only be used if the [automatic cancellation of redundant pipelines feature](../pipelines/settings.md#auto-cancel-pending-pipelines) +This value is used only if the [automatic cancellation of redundant pipelines feature](../pipelines/settings.md#auto-cancel-pending-pipelines) is enabled. -When enabled, a pipeline on the same branch will be canceled when: +When enabled, a pipeline on the same branch is canceled when: - It's made redundant by a newer pipeline run. - Either all jobs are set as interruptible, or any uninterruptible jobs haven't started. -Pending jobs are always considered interruptible. - -TIP: **Tip:** Set jobs as interruptible that can be safely canceled once started (for instance, a build job). +Pending jobs are always considered interruptible. + Here is a simple example: ```yaml @@ -3806,17 +3827,16 @@ step-2: step-3: stage: stage3 script: - - echo "Because step-2 can not be canceled, this step will never be canceled, even though set as interruptible." + - echo "Because step-2 can not be canceled, this step can never be canceled, even though it's set as interruptible." interruptible: true ``` -In the example above, a new pipeline run will cause an existing running pipeline to be: +In the example above, a new pipeline run causes an existing running pipeline to be: - Canceled, if only `step-1` is running or pending. - Not canceled, once `step-2` starts running. -NOTE: **Note:** -Once an uninterruptible job is running, the pipeline will never be canceled, regardless of the final job's state. +When an uninterruptible job is running, the pipeline can never be canceled, regardless of the final job's state. ### `resource_group` @@ -3826,12 +3846,13 @@ Sometimes running multiple jobs or pipelines at the same time in an environment can lead to errors during the deployment. To avoid these errors, the `resource_group` attribute can be used to ensure that -the runner doesn't run certain jobs simultaneously. +the runner doesn't run certain jobs simultaneously. Resource groups behave similar +to semaphores in other programming languages. When the `resource_group` key is defined for a job in `.gitlab-ci.yml`, job executions are mutually exclusive across different pipelines for the same project. If multiple jobs belonging to the same resource group are enqueued simultaneously, -only one of the jobs is picked by the runner, and the other jobs wait until the +only one of the jobs is picked by the runner. The other jobs wait until the `resource_group` is free. Here is a simple example: @@ -3842,17 +3863,14 @@ deploy-to-production: resource_group: production ``` -In this case, if a `deploy-to-production` job is running in a pipeline, and a new -`deploy-to-production` job is created in a different pipeline, it won't run until -the currently running/pending `deploy-to-production` job is finished. As a result, -you can ensure that concurrent deployments will never happen to the production environment. +In this case, two `deploy-to-production` jobs in two separate pipelines can never run at the same time. As a result, +you can ensure that concurrent deployments never happen to the production environment. There can be multiple `resource_group`s defined per environment. A good use case for this -is when deploying to physical devices. You may have more than one physical device, and each -one can be deployed to, but there can be only one deployment per device at any given time. +is when deploying to physical devices. You may have multiple physical devices that +can be deployed to, but there can be only one deployment per device at any given time. -NOTE: **Note:** -This key can only contain letters, digits, `-`, `_`, `/`, `$`, `{`, `}`, `.`, and spaces. +The `resource_group` value can only contain letters, digits, `-`, `_`, `/`, `$`, `{`, `}`, `.`, and spaces. It can't start or end with `/`. For more information, see [Deployments Safety](../environments/deployment_safety.md). @@ -3962,7 +3980,11 @@ The title of each milestone the release is associated with. #### `release:released_at` The date and time when the release is ready. Defaults to the current date and time if not -defined. Expected in ISO 8601 format (2019-03-15T08:00:00Z). +defined. Should be enclosed in quotes and expressed in ISO 8601 format. + +```json +released_at: '2021-03-15T08:00:00Z' +``` #### Complete example for `release` @@ -3990,7 +4012,7 @@ tags. These options cannot be used together, so choose one: - 'm1' - 'm2' - 'm3' - released_at: '2020-07-15T08:00:00Z' # Optional, will auto generate if not defined, or can use a variable. + released_at: '2020-07-15T08:00:00Z' # Optional, is auto generated if not defined, or can use a variable. ``` - To create a release automatically when commits are pushed or merged to the default branch, @@ -4036,9 +4058,14 @@ tags. These options cannot be used together, so choose one: - 'm1' - 'm2' - 'm3' - released_at: '2020-07-15T08:00:00Z' # Optional, will auto generate if not defined, or can use a variable. + released_at: '2020-07-15T08:00:00Z' # Optional, is auto generated if not defined, or can use a variable. ``` +#### Release assets as Generic packages + +You can use [Generic packages](../../user/packages/generic_packages/) to host your release assets. +For a complete example of how to do this, see the [example in the repository](https://gitlab.com/gitlab-org/release-cli/-/tree/master/docs/examples/release-assets-as-generic-package/). + #### `releaser-cli` command line The entries under the `:release` node are transformed into a `bash` command line and sent @@ -4056,14 +4083,16 @@ release-cli create --name "Release $CI_COMMIT_SHA" --description "Created using > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/33014) in GitLab 13.4. `secrets` indicates the [CI Secrets](../secrets/index.md) this job needs. It should be a hash, -and the keys should be the names of the environment variables the job needs to access the secrets. +and the keys should be the names of the environment variables that are made available to the job. +The value of each secret is saved in a temporary file. This file's path is stored in these +environment variables. #### `secrets:vault` **(PREMIUM)** > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/28321) in GitLab 13.4. `vault` keyword specifies secrets provided by [Hashicorp's Vault](https://www.vaultproject.io/). -This syntax has multiple forms. The shortest form asssumes the use of the +This syntax has multiple forms. The shortest form assumes the use of the [KV-V2](https://www.vaultproject.io/docs/secrets/kv/kv-v2) secrets engine, mounted at the default path `kv-v2`. The last part of the secret's path is the field to fetch the value for: @@ -4072,7 +4101,7 @@ field to fetch the value for: job: secrets: DATABASE_PASSWORD: - vault: production/db/password # translates to secret `kv-v2/data/production/db`, field `password` + vault: production/db/password # translates to secret `kv-v2/data/production/db`, field `password` ``` You can specify a custom secrets engine path by adding a suffix starting with `@`: @@ -4081,7 +4110,7 @@ You can specify a custom secrets engine path by adding a suffix starting with `@ job: secrets: DATABASE_PASSWORD: - vault: production/db/password@ops # translates to secret `ops/data/production/db`, field `password` + vault: production/db/password@ops # translates to secret `ops/data/production/db`, field `password` ``` In the detailed form of the syntax, you can specify all details explicitly: @@ -4131,34 +4160,40 @@ Read more on [GitLab Pages user documentation](../../user/project/pages/index.md > Introduced in GitLab Runner v0.5.0. -NOTE: **Note:** -Integers (as well as strings) are legal both for variable's name and value. -Floats are not legal and can't be used. +Variables are configurable values that are passed to jobs. They can be set +globally and per-job. + +There are two types of variables. + +- [Custom variables](../variables/README.md#custom-environment-variables): + You can define their values in the `.gitlab-ci.yml` file, in the GitLab UI, + or by using the API. +- [Predefined variables](../variables/predefined_variables.md): + These values are set by the runner itself. + One example is `CI_COMMIT_REF_NAME`, which is the branch or tag the project is built for. -Variables are configurable values in `.gitlab-ci.yml` that are passed to jobs. -They can be set globally and per-job. -When you use the `variables` keyword in jobs, it overrides the global -YAML variables and predefined ones of the same name. +After you define a variable, you can use it in all executed commands and scripts. -Variables are stored in the Git repository and are meant for non-sensitive -project configuration, for example: +Variables are meant for non-sensitive project configuration, for example: ```yaml variables: DATABASE_URL: "postgres://postgres@postgres/my_database" ``` -You can use these variables later in all executed commands and scripts. -The YAML-defined variables are also set to all created service containers, -so that you can fine tune them. +You can use integers and strings for the variable's name and value. +You cannot use floats. + +If you define a variable at the top level of the `gitlab-ci.yml` file, it is global, +meaning it applies to all jobs. + +If you define a variable within a job, it's available to that job only. -Except for the user-defined variables, there are also variables [set up by the -runner itself](../variables/README.md#predefined-environment-variables). -One example would be `CI_COMMIT_REF_NAME`, which has the value of -the branch or tag name the project is built for. Apart from the variables -you can set in `.gitlab-ci.yml`, there are also environment -[variables](../variables/README.md#gitlab-cicd-environment-variables), -which can be set in the GitLab UI. +If a variable of the same name is defined globally and for a specific job, the +[job-specific variable is used](../variables/README.md#priority-of-environment-variables). + +All YAML-defined variables are also set to any linked +[service containers](../docker/using_docker_images.md#what-is-a-service). [YAML anchors for variables](#yaml-anchors-for-variables) are available. @@ -4169,12 +4204,9 @@ Learn more about [variables and their priority](../variables/README.md). > - Introduced in GitLab 8.9 as an experimental feature. > - `GIT_STRATEGY=none` requires GitLab Runner v1.7+. -CAUTION: **Caution:** -May change or be removed completely in future releases. - You can set the `GIT_STRATEGY` used for getting recent application code, either globally or per-job in the [`variables`](#variables) section. If left -unspecified, the default from project settings will be used. +unspecified, the default from the project settings is used. There are three possible values: `clone`, `fetch`, and `none`. @@ -4195,10 +4227,11 @@ variables: GIT_STRATEGY: fetch ``` -`none` also re-uses the local working copy, but skips all Git operations -(including GitLab Runner's pre-clone script, if present). It's mostly useful -for jobs that operate exclusively on artifacts (for example, `deploy`). Git repository -data may be present, but it's certain to be out of date, so you should only +`none` also re-uses the local working copy. However, it skips all Git operations, +including GitLab Runner's pre-clone script, if present. + +It's useful for jobs that operate exclusively on artifacts, like a deployment job. +Git repository data may be present, but it's likely out-of-date. You should only rely on files brought into the local working copy from cache or artifacts. ```yaml @@ -4222,10 +4255,10 @@ globally or per-job in the [`variables`](#variables) section. There are three possible values: `none`, `normal`, and `recursive`: -- `none` means that submodules won't be included when fetching the project +- `none` means that submodules are not included when fetching the project code. This is the default, which matches the pre-v1.10 behavior. -- `normal` means that only the top-level submodules will be included. It's +- `normal` means that only the top-level submodules are included. It's equivalent to: ```shell @@ -4234,7 +4267,7 @@ There are three possible values: `none`, `normal`, and `recursive`: ``` - `recursive` means that all submodules (including submodules of submodules) - will be included. This feature needs Git v1.8.1 and later. When using a + are included. This feature needs Git v1.8.1 and later. When using a GitLab Runner with an executor not based on Docker, make sure the Git version meets that requirement. It's equivalent to: @@ -4243,7 +4276,7 @@ There are three possible values: `none`, `normal`, and `recursive`: git submodule update --init --recursive ``` -Note that for this feature to work correctly, the submodules must be configured +For this feature to work correctly, the submodules must be configured (in `.gitmodules`) with either: - the HTTP(S) URL of a publicly-accessible repository, or @@ -4259,15 +4292,15 @@ The `GIT_CHECKOUT` variable can be used when the `GIT_STRATEGY` is set to either specified, it defaults to true. You can set them globally or per-job in the [`variables`](#variables) section. -If set to `false`, the runner will: +If set to `false`, the runner: -- when doing `fetch` - update the repository and leave working copy on +- when doing `fetch` - updates the repository and leaves the working copy on the current revision, -- when doing `clone` - clone the repository and leave working copy on the +- when doing `clone` - clones the repository and leaves the working copy on the default branch. -Having this setting set to `true` will mean that for both `clone` and `fetch` -strategies the runner will checkout the working copy to a revision related +If `GIT_CHECKOUT` is set to `true`, both `clone` and `fetch` work the same way. +The runner checks out the working copy of a revision related to the CI pipeline: ```yaml @@ -4313,7 +4346,7 @@ script: The `GIT_FETCH_EXTRA_FLAGS` variable is used to control the behavior of `git fetch`. You can set it globally or per-job in the [`variables`](#variables) section. -`GIT_FETCH_EXTRA_FLAGS` accepts all possible options of the [`git fetch`](https://git-scm.com/docs/git-fetch) command, but please note that `GIT_FETCH_EXTRA_FLAGS` flags will be appended after the default flags that can't be modified. +`GIT_FETCH_EXTRA_FLAGS` accepts all options of the [`git fetch`](https://git-scm.com/docs/git-fetch) command. However, `GIT_FETCH_EXTRA_FLAGS` flags are appended after the default flags that can't be modified. The default flags are: @@ -4335,7 +4368,7 @@ script: - ls -al cache/ ``` -The configuration above will result in `git fetch` being called this way: +The configuration above results in `git fetch` being called this way: ```shell git fetch origin $REFSPECS --depth 50 --prune @@ -4347,13 +4380,13 @@ Where `$REFSPECS` is a value provided to the runner internally by GitLab. > Introduced in GitLab, it requires GitLab Runner v1.9+. -You can set the number for attempts the running job will try to execute each -of the following stages: +You can set the number of attempts that the running job tries to execute +the following stages: | Variable | Description | |-----------------------------------|--------------------------------------------------------| | **ARTIFACT_DOWNLOAD_ATTEMPTS** | Number of attempts to download artifacts running a job | -| **EXECUTOR_JOB_SECTION_ATTEMPTS** | [Since GitLab 12.10](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4450), the number of attempts to run a section in a job after a [`No Such Container`](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4450) error ([Docker executor](https://docs.gitlab.com/runner/executors/docker.html) only). | +| **EXECUTOR_JOB_SECTION_ATTEMPTS** | [In GitLab 12.10](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4450) and later, the number of attempts to run a section in a job after a [`No Such Container`](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4450) error ([Docker executor](https://docs.gitlab.com/runner/executors/docker.html) only). | | **GET_SOURCES_ATTEMPTS** | Number of attempts to fetch sources running a job | | **RESTORE_CACHE_ATTEMPTS** | Number of attempts to restore the cache running a job | @@ -4368,27 +4401,52 @@ variables: You can set them globally or per-job in the [`variables`](#variables) section. +### Fallback cache key + +> [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/1534) in GitLab Runner 13.4. + +You can use the `$CI_COMMIT_REF_SLUG` variable to specify your [`cache:key`](#cachekey). +For example, if your `$CI_COMMIT_REF_SLUG` is `test` you can set a job +to download cache that's tagged with `test`. + +If a cache with this tag is not found, you can use `CACHE_FALLBACK_KEY` to +specify a cache to use when none exists. + +For example: + +```yaml +variables: + CACHE_FALLBACK_KEY: fallback-key + +cache: + key: "$CI_COMMIT_REF_SLUG" + paths: + - binaries/ +``` + +In this example, if the `$CI_COMMIT_REF_SLUG` is not found, the job uses the key defined +by the `CACHE_FALLBACK_KEY` variable. + ### Shallow cloning > Introduced in GitLab 8.9 as an experimental feature. -NOTE: **Note:** -As of GitLab 12.0, newly created projects will automatically have a [default `git depth` value of `50`](../pipelines/settings.md#git-shallow-clone). - -You can specify the depth of fetching and cloning using `GIT_DEPTH`. This does a -shallow clone of the repository and can significantly speed up cloning for -repositories with a large number of commits or old, large binaries. The value is +You can specify the depth of fetching and cloning using `GIT_DEPTH`. +`GIT_DEPTH` does a shallow clone of the repository and can significantly speed up cloning. +It can be helpful for repositories with a large number of commits or old, large binaries. The value is passed to `git fetch` and `git clone`. -NOTE: **Note:** -If you use a depth of 1 and have a queue of jobs or retry +In GitLab 12.0 and later, newly-created projects automatically have a +[default `git depth` value of `50`](../pipelines/settings.md#git-shallow-clone). + +If you use a depth of `1` and have a queue of jobs or retry jobs, jobs may fail. -Since Git fetching and cloning is based on a ref, such as a branch name, runners -can't clone a specific commit SHA. If there are multiple jobs in the queue, or -you're retrying an old job, the commit to be tested needs to be within the +Git fetching and cloning is based on a ref, such as a branch name, so runners +can't clone a specific commit SHA. If multiple jobs are in the queue, or +you're retrying an old job, the commit to be tested must be within the Git history that is cloned. Setting too small a value for `GIT_DEPTH` can make -it impossible to run these old commits. You will see `unresolved reference` in +it impossible to run these old commits and `unresolved reference` is displayed in job logs. You should then reconsider changing `GIT_DEPTH` to a higher value. Jobs that rely on `git describe` may not work correctly when `GIT_DEPTH` is @@ -4407,11 +4465,6 @@ You can set it globally or per-job in the [`variables`](#variables) section. > [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2211) in GitLab Runner 11.10. -NOTE: **Note:** -This can only be used when `custom_build_dir` is enabled in the [runner's -configuration](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscustom_build_dir-section). -This is the default configuration for `docker` and `kubernetes` executor. - By default, GitLab Runner clones the repository in a unique subpath of the `$CI_BUILDS_DIR` directory. However, your project might require the code in a specific directory (Go projects, for example). In that case, you can specify @@ -4431,12 +4484,17 @@ The `GIT_CLONE_PATH` has to always be within `$CI_BUILDS_DIR`. The directory set is dependent on executor and configuration of [runners.builds_dir](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section) setting. +This can only be used when `custom_build_dir` is enabled in the +[runner's configuration](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscustom_build_dir-section). +This is the default configuration for the `docker` and `kubernetes` executors. + #### Handling concurrency -An executor using a concurrency greater than `1` might lead -to failures because multiple jobs might be working on the same directory if the `builds_dir` +An executor that uses a concurrency greater than `1` might lead +to failures. Multiple jobs might be working on the same directory if the `builds_dir` is shared between jobs. -GitLab Runner does not try to prevent this situation. It's up to the administrator + +The runner does not try to prevent this situation. It's up to the administrator and developers to comply with the requirements of runner configuration. To avoid this scenario, you can use a unique path within `$CI_BUILDS_DIR`, because runner @@ -4503,15 +4561,20 @@ need to be used to merge arrays. > Introduced in GitLab 8.6 and GitLab Runner v1.1.1. -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. When there is duplicate keys, GitLab will -perform a reverse deep merge based on the keys. +YAML has a feature called 'anchors' that you can use to duplicate +content across your document. + +Use anchors to duplicate or inherit properties. Use anchors with [hidden jobs](#hide-jobs) +to provide templates for your jobs. When there are duplicate keys, GitLab +performs a reverse deep merge based on the keys. + +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. Instead +of using YAML anchors, you can use the [`extends` keyword](#extends). -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 -having their own custom `script` defined: +The following example uses anchors and map merging. It creates two jobs, +`test1` and `test2`, that inherit the parameters of `.job_template`, each +with their own custom `script` defined: ```yaml .job_template: &job_definition # Hidden key that defines an anchor named 'job_definition' @@ -4559,9 +4622,9 @@ test2: - test2 project ``` -Let's see another one example. This time we will use anchors to define two sets -of services. This will create two jobs, `test:postgres` and `test:mysql`, that -will share the `script` directive defined in `.job_template`, and the `services` +Let's see another example. This time we use anchors to define two sets +of services. This configuration creates two jobs, `test:postgres` and `test:mysql`, that +share the `script` directive defined in `.job_template`, and the `services` directive defined in `.postgres_services` and `.mysql_services` respectively: ```yaml @@ -4630,15 +4693,8 @@ test:mysql: - 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. Instead -of using YAML anchors, you can use the [`extends` keyword](#extends). +You can see that the hidden jobs are conveniently used as templates, and +`tags: [dev]` has been overwritten by `tags: [postgres]`. #### YAML anchors for `before_script` and `after_script` @@ -4692,7 +4748,7 @@ job_name: 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 +In the example below, we override the `GIT_STRATEGY` variable without affecting the use of the `SAMPLE_VARIABLE` variable: ```yaml @@ -4701,7 +4757,7 @@ variables: &global-variables SAMPLE_VARIABLE: sample_variable_value ANOTHER_SAMPLE_VARIABLE: another_sample_variable_value -# a job that needs to set the GIT_STRATEGY variable, yet depend on global variables +# a job that must set the GIT_STRATEGY variable, yet depend on global variables job_no_git_strategy: stage: cleanup variables: @@ -4723,8 +4779,8 @@ lines where the job is defined: # - run test ``` -You can instead start its name with a dot (`.`) and it won't be processed by -GitLab CI/CD. In the following example, `.hidden_job` will be ignored: +Instead, you can start its name with a dot (`.`) and it is not processed by +GitLab CI/CD. In the following example, `.hidden_job` is ignored: ```yaml .hidden_job: @@ -4739,18 +4795,18 @@ into templates. ## Skip Pipeline If your commit message contains `[ci skip]` or `[skip ci]`, using any -capitalization, the commit will be created but the pipeline will be skipped. +capitalization, the commit is created but the pipeline is skipped. Alternatively, one can pass the `ci.skip` [Git push option](../../user/project/push_options.md#push-options-for-gitlab-cicd) if using Git 2.10 or newer. ## Processing Git pushes -GitLab will create at most 4 branch and tag pipelines when -pushing multiple changes in single `git push` invocation. +GitLab creates at most four branch and tag pipelines when +pushing multiple changes in a single `git push` invocation. -This limitation does not affect any of the updated Merge Request pipelines. -All updated Merge Requests will have a pipeline created when using +This limitation does not affect any of the updated merge request pipelines. +All updated merge requests have a pipeline created when using [pipelines for merge requests](../merge_request_pipelines/index.md). ## Deprecated parameters diff --git a/doc/ci/yaml/img/ci_config_visualization_hover_v13_5.png b/doc/ci/yaml/img/ci_config_visualization_hover_v13_5.png Binary files differnew file mode 100644 index 00000000000..e6c85bd39e4 --- /dev/null +++ b/doc/ci/yaml/img/ci_config_visualization_hover_v13_5.png diff --git a/doc/ci/yaml/img/ci_config_visualization_v13_5.png b/doc/ci/yaml/img/ci_config_visualization_v13_5.png Binary files differnew file mode 100644 index 00000000000..0aee5cff7be --- /dev/null +++ b/doc/ci/yaml/img/ci_config_visualization_v13_5.png diff --git a/doc/ci/yaml/includes.md b/doc/ci/yaml/includes.md index f7ed7248dc4..d7945617dc9 100644 --- a/doc/ci/yaml/includes.md +++ b/doc/ci/yaml/includes.md @@ -73,10 +73,11 @@ automatically fetched and evaluated along with the content of `.gitlab-ci.yml`. Content of `https://gitlab.com/awesome-project/raw/master/.before-script-template.yml`: ```yaml -before_script: - - apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs - - gem install bundler --no-document - - bundle install --jobs $(nproc) "${FLAGS[@]}" +default: + before_script: + - apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs + - gem install bundler --no-document + - bundle install --jobs $(nproc) "${FLAGS[@]}" ``` Content of `.gitlab-ci.yml`: diff --git a/doc/ci/yaml/visualization.md b/doc/ci/yaml/visualization.md new file mode 100644 index 00000000000..ac5f5c8fd14 --- /dev/null +++ b/doc/ci/yaml/visualization.md @@ -0,0 +1,46 @@ +# Visualize your CI/CD configuration + +> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/241722) in GitLab 13.5. +> - It's [deployed behind a feature flag](../../user/feature_flags.md), disabled by default. +> - It's disabled on GitLab.com. +> - It's not recommended for production use. +> - To use it in GitLab self-managed instances, ask a GitLab administrator to [enable it](#enable-or-disable-cicd-configuration-visualization). **(CORE ONLY)** + +CAUTION: **Warning:** +This feature might not be available to you. Check the **version history** note above for details. + +To see a visualization of your `gitlab-ci.yml` configuration, navigate to any CI/CD +configuration file and click on the `Visualization` tab. The visualization shows +all stages and jobs. [`needs`](README.md#needs) relationships are displayed as lines +connecting jobs together, showing the hierarchy of execution: + +![CI Config Visualization](img/ci_config_visualization_v13_5.png) + +Hovering on a job highlights its `needs` relationships: + +![CI Config Visualization on hover](img/ci_config_visualization_hover_v13_5.png) + +If the configuration does not have any `needs` relationships, then no lines are drawn because +each job depends only on the previous stage being completed successfully. + +You can only preview one `gitlab-ci.yml` file at a time. Configuration imported with +[`includes`](README.md#include) is ignored and not included in the visualization. + +## Enable or disable CI/CD configuration visualization **(CORE ONLY)** + +CI/CD configuration visualization is under development and not ready for production use. It is +deployed behind a feature flag that is **disabled by default**. +[GitLab administrators with access to the GitLab Rails console](../../administration/feature_flags.md) +can enable it. + +To enable it: + +```ruby +Feature.enable(:gitlab_ci_yml_preview) +``` + +To disable it: + +```ruby +Feature.disable(:gitlab_ci_yml_preview) +``` |