Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/doc/ci/jobs
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-25 03:11:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-25 03:11:06 +0300
commit9b124bc39e0902fffd4285d077c70edbfbce3b36 (patch)
tree5c8bdf0ae3305ce49c1bad5aa2ed29a93672065d /doc/ci/jobs
parent8a0ba602908b4360f52bf64fb715585d6245079e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/ci/jobs')
-rw-r--r--doc/ci/jobs/job_control.md29
1 files changed, 29 insertions, 0 deletions
diff --git a/doc/ci/jobs/job_control.md b/doc/ci/jobs/job_control.md
index b8b05426297..c415df01f06 100644
--- a/doc/ci/jobs/job_control.md
+++ b/doc/ci/jobs/job_control.md
@@ -290,6 +290,35 @@ You can use the `$` character for both variables and paths. For example, if the
`$DOCKERFILES_DIR` variable exists, its value is used. If it does not exist, the
`$` is interpreted as being part of a path.
+## Reuse rules in different jobs
+
+> [Introduced in](https://gitlab.com/gitlab-org/gitlab/-/issues/322992) GitLab 14.3.
+
+Use [`!reference` tags](../yaml/index.md#reference-tags) to reuse rules in different
+jobs. You can combine `!reference` rules with regular job-defined rules:
+
+```yaml
+.default_rules:
+ rules:
+ - if: $CI_PIPELINE_SOURCE == "schedule"
+ when: never
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
+
+job1:
+ rules:
+ - !reference [.default_rules, rules]
+ script:
+ - echo "This job runs for the default branch, but not schedules."
+
+job2:
+ rules:
+ - !reference [.default_rules, rules]
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"
+ script:
+ - echo "This job runs for the default branch, but not schedules."
+ - echo "It also runs for merge requests."
+```
+
## Specify when jobs run with `only` and `except`
You can use [`only`](../yaml/index.md#only--except) and [`except`](../yaml/index.md#only--except)