![](/img/trans.png)
[英]Why is my ignore command being ignored in my Gitlab pipeline yaml file?
[英]Why in the Gitlab Pipeline is my workflow rule being ignored?
這是我的 gitlab-ci.yml:
workflow:
rules:
- if: $CI_COMMIT_MESSAGE =~ /-draft$/
when: never
- if: $CI_PIPELINE_SOURCE == "push"
include:
- '/gitlab-ci/includes.yml'
- '/idt-test-stub/gitlab-ci.yml'
variables:
ALPINE_VERSION: "3.16"
NODE_VERSION: "14-alpine"
ESLINT_CONFIG_PATH: "./.eslintrc.js"
SOURCE_DIR: "."
BUILD_TYPE: MAVEN
MVN_CLI_OPTS: "--batch-mode"
MVN_OPTS: "-Dmaven.repo.local=.m2-local -f wiremock-java/pom.xml"
MAVEN_IMAGE: "maven:3-jdk-11"
stages:
- test
- code-quality
- code-test
- code-analysis
- verify
- transform
- application-build
- image-build
- move-container-tests
- container-image-test
- image-push
.branches: &branches
only:
- branches
todo-check:
<<: *branches
shell-check:
<<: *branches
docker-lint:
<<: *branches
unit-test:
<<: *branches
artifacts:
expire_in: 20 mins
paths:
- ./coverage
verify:
<<: *branches
stage: verify
image: node:$NODE_VERSION
script:
- npm install
- ./run-verify.sh
tags:
- docker-in-docker-privilegedx
我的理解是,如果我在我的提交消息中提交包含“草稿”一詞的更改,當我推送它時,我的工作流規則應該停止管道運行,但它沒有。
管道中的所有作業都會運行。
工作流規則部分是直接從 Gitlab 文檔中復制的,它是這樣說的:
在以下示例中:
管道為所有推送事件(對分支和新標簽的更改)運行。 提交消息中帶有 -draft 的推送事件管道不會運行,因為它們被設置為 when: never。 調度或合並請求的管道也不運行,因為沒有規則對它們評估為真。
這是因為 /-draft $
/-draft$/
末尾的 $ 。 $
是正則表達式中的特殊字符,匹配一段文本的結尾。
即使嘗試在 Gitlab 中使用$
並使用諸如“Commit -draft”之類的提交消息,仍然會失敗。 我不知道為什么。 也許他們根本不支持$
字符。
如果你只是想檢查你的提交消息是否包含draft
這個詞,你可以省略-
和末尾的$
:
workflow:
rules:
- if: $CI_COMMIT_MESSAGE =~ /draft/
when: never
我在 Gitlab 上測試過:
附言。 我已經在 Gitlab 上創建了一個合並請求來修復他們文檔的這一部分,所以讓我們看看他們怎么說。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.