summaryrefslogtreecommitdiff
path: root/doc/ci/jobs
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-25 18:10:08 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-25 18:10:08 +0000
commit421200ab0d5bbc1a3745cebc51b8d300ebbd766a (patch)
treee525e87966907a65d6a89b148f9296306eb15aa1 /doc/ci/jobs
parent5f85444a43df1c5f025b520fdbc682cbf95d3ca0 (diff)
downloadgitlab-ce-421200ab0d5bbc1a3745cebc51b8d300ebbd766a.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/ci/jobs')
-rw-r--r--doc/ci/jobs/job_control.md27
1 files changed, 27 insertions, 0 deletions
diff --git a/doc/ci/jobs/job_control.md b/doc/ci/jobs/job_control.md
index 0d5357e63ad..b45929fd78f 100644
--- a/doc/ci/jobs/job_control.md
+++ b/doc/ci/jobs/job_control.md
@@ -957,6 +957,33 @@ For example:
Pattern matching is case-sensitive by default. Use the `i` flag modifier to make a
pattern case-insensitive. For example: `/pattern/i`.
+#### Store the regex pattern in a variable
+
+> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/35438) in GitLab 15.0 [with a flag](../../administration/feature_flags.md) named `ci_fix_rules_if_comparison_with_regexp_variable`, disabled by default.
+> - [Generally available](https://gitlab.com/gitlab-org/gitlab/-/issues/359740) and feature flag `ci_fix_rules_if_comparison_with_regexp_variable` removed in GitLab 15.1.
+
+Variables on the right side of `=~` and `!~` expressions are evaluated as regular expressions.
+The regular expression must be enclosed in forward slashes (`/`). For example:
+
+```yaml
+variables:
+ pattern: '/^ab.*/'
+
+regex-job1:
+ variables:
+ teststring: 'abcde'
+ script: echo "This job will run, because 'abcde' matches the /^ab.*/ pattern."
+ rules:
+ - if: '$teststring =~ $pattern'
+
+regex-job2:
+ variables:
+ teststring: 'fghij'
+ script: echo "This job will not run, because 'fghi' does not match the /^ab.*/ pattern."
+ rules:
+ - if: '$teststring =~ $pattern'
+```
+
### Join variable expressions together with `&&` or `||`
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/62867) in GitLab 12.0