Reputation: 125
Lets Imagine I want to have 2 different CI Pipelines in gitlab. The first one should start with every push on any branch the other one only when the commit title ends with deploy.
How do I realise that?
So my Idea:
.gitlab-ci.yml
stages:
- pre
- build
include:
- local: ci/a.gitlab-ci.yml
- local: ci/b.gitlab-ci.yml
a.gitlab-ci.yml
workflow:
rules:
# only triggered by "-deploy" at the end of commit
- if: $CI_COMMIT_TITLE == /-deploy$/
test-job1:
stage: pre
script:
- echo "Workflow a runs pre."
tags:
- x86
test-job2:
stage: build
script:
- echo "Workflow a runs build."
tags:
- x86
b.gitlab-ci.yml
workflow:
rules:
# only triggered if commit does not end with "-deploy"
- if: $CI_COMMIT_TITLE =~ /-deploy$/
test-job1:
stage: pre
script:
- echo "Workflow b runs pre."
tags:
- x86
test-job2:
stage: build
script:
- echo "Workflow b runs build."
tags:
- x86
Upvotes: 5
Views: 6794
Reputation: 40861
To achieve the effect you want, your best bet would be to use include:rules:
for this instead of workflow:rules:
.
I believe you also may have a small error in the regex matching rule. You probably wanted to be using the regex match operator (=~
i.e., does match the pattern) in the first case and the negative match re operator (!~
i.e., does not match the pattern) in the second case.
include:
- local: ci/a.gitlab-ci.yml
rules:
- if: $CI_COMMIT_TITLE =~ /-deploy$/
- local: ci/b.gitlab-ci.yml
rules:
- if: $CI_COMMIT_TITLE !~ /-deploy$/
Then remove the workflow:rules:
from each respective template.
Upvotes: 10