我希望我的Gitlab作业在提交消息以特定字符串启动时运行而不是:[maven-scm]
因此,我的..gitlab ci.yaml文件中有以下配置:
image: maven:3.6.3-jdk-11-slim
stages:
- test
test:
stage: test
cache:
key: all
paths:
- ./.m2/repository
script:
- mvn clean checkstyle:check test spotbugs:check
rules:
- if: '$CI_COMMIT_MESSAGE !~ /^\[maven-scm\] .*$/'
我的提交消息是:[maven-scm] I hope the test job does not run
但是测试工作仍然让我感到沮丧。我查看了GitLab的规则文档,但找不到作业仍然运行的原因。我不确定我是不是漏了什么东西。
如果有人能给我指明正确的方向,那就太好了。
更新:
我尝试了唯一的/唯一的子句,而不是规则。我将yaml文件修改如下:
image: maven:3.6.3-jdk-11-slim
stages:
- test
test:
stage: test
cache:
key: all
paths:
- ./.m2/repository
script:
- mvn clean checkstyle:check test spotbugs:check
except:
variables:
- $CI_COMMIT_MESSAGE =~ /^\[maven-scm\] .*$/
当提交消息以[maven-scm]
开始时,作业仍然运行。
发布于 2020-08-15 20:55:59
这是一个棘手的问题,因为问题不在rules
部分。问题实际上是正则表达式。您只需要在提交消息开始时指定所需的模式,即不需要以下通配符。下列工程并经测试:
test-rules:
stage: test
rules:
- if: '$CI_COMMIT_MESSAGE !~ /^\[maven-scm\] /'
script:
- echo "$CI_COMMIT_MESSAGE"
以下提交消息对此进行了测试:
This commit message will run the job
This commit message [maven-scm] will run the job
[maven-scm] This commit message will NOT run the job
FYI GitLab文档指定rules
优于only/except
,因此最好坚持使用rules: if
。见只有-基本。
https://stackoverflow.com/questions/63426990
复制相似问题