[英]Use multiple 'workflows' in gitlab ci?
Lets Imagine I want to have 2 different CI Pipelines in gitlab.让我们想象一下,我想在 gitlab 中有 2 个不同的 CI 管道。 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 .gitlab-ci.yml
stages:
- pre
- build
include:
- local: ci/a.gitlab-ci.yml
- local: ci/b.gitlab-ci.yml
a.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 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
To achieve the effect you want, your best bet would be to use include:rules:
for this instead of workflow:rules:
.为了达到你想要的效果,你最好的办法是使用
include:rules:
而不是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 (
=~
ie, does match the pattern) in the first case and the negative match re operator ( !~
ie, 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.然后从每个相应的模板中删除
workflow:rules:
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.