英文:
Gitab CI : rules with changes to a dir/path
问题
我正在尝试在我的CI中添加这个逻辑:
- 不要在
merge_request_events
或合并请求的目标分支受保护且对e2e
目录中的任何文件进行更改时将作业添加到流水线中。 - 当要合并到的分支是以下之一时添加作业:
dev
、test
或demo
。 - 在任何其他情况下不要将作业添加到流水线。
以下是我的规则:
.ci-rules:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_MERGE_REQUEST_TARGET_BRANCH_PROTECTED == "true"'
changes:
- "e2e/**/*"
when: never
- if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
when: always
- when: never
build:
rules:
- !reference [.ci-rules, rules]
stage: build
script:
- echo "do something"
allow_failure: false
问题:
当我对e2e
目录中的文件进行更改时,作业仍然会添加到流水线中。
我将不胜感激任何帮助。
英文:
I'm trying to add this logic in my CI :
- don't add job to pipeline on
merge_request_events
or when merge request target branch is protected and when changes are made to any file in thee2e
directory - add job when the branch to which I'm merging to is one of the following
dev
,test
ordemo
- don't add job to pipeline in any other case.
Here are my rules
.ci-rules:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" || $CI_MERGE_REQUEST_TARGET_BRANCH_PROTECTED == "true"'
changes:
- "e2e/**/*"
when: never
- if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
when: always
- when: never
build:
rules:
- !reference [.ci-rules, rules]
stage: build
script:
- echo "do something"
allow_failure: false
Issue:
When I make changes to files in e2e
directory only the job is still added to the pipeline.
I'd appreciate any help
答案1
得分: 0
我用以下方式解决了这个问题:
.ci-rules:
rules:
- if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
changes:
- "e2e/**/*"
when: never
- if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
when: always
- when: never
英文:
I solved this with the following
.ci-rules:
rules:
- if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
changes:
- "e2e/**/*"
when: never
- if: '$CI_COMMIT_REF_NAME == "dev" || $CI_COMMIT_REF_NAME == "test" || $CI_COMMIT_REF_NAME == "demo"'
when: always
- when: never
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论