Bib*_*rlt 6 continuous-integration continuous-deployment gitlab gitlab-ci cicd
我正在尝试使用“规则”和“仅”关键字来定义合并请求、推送到开发分支和推送到主分支之间的管道行为。
我注意到 Gitlab CI 中有几个奇怪的行为,让我们在我的 merge_requests 管道中看看。
image: "python:3.8"
stages:
- test_without_only_policy
- test_with_only_policy
test_without_only_policy:
stage: test_without_only_policy
when: manual
script:
- echo "Yay, I am in the pipeline"
test_with_only_policy:
stage: test_with_only_policy
script:
- echo "I am always in the pipeline"
Run Code Online (Sandbox Code Playgroud)
一切都按预期进行,很棒
image: "python:3.8"
stages:
- test_without_only_policy
- test_with_only_policy
test_without_only_policy:
stage: test_without_only_policy
when: manual
script:
- echo "No, I am not in the pipeline anymore"
test_with_only_policy:
stage: test_with_only_policy
only:
- merge_requests
script:
- echo "I am always in the pipeline"
Run Code Online (Sandbox Code Playgroud)
为什么第一份没有规则或“唯一”政策的工作消失了?
image: "python:3.8"
stages:
- test_without_only_policy
- test_with_only_policy
test_without_only_policy:
stage: test_without_only_policy
when: manual
script:
- echo "No, I am not in the pipeline anymore"
test_with_only_policy:
stage: test_with_only_policy
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: manual
script:
- echo "I am always in the pipeline"
Run Code Online (Sandbox Code Playgroud)
为什么第一份没有规则或“唯一”政策的工作消失了?
谢谢您的帮助,我不明白为什么当我在其他工作中添加规则时我的工作就会消失。
根据Merge Request Pipelines 的文档,如果您有一个管道,其中只有某些作业使用 only/ except/rules with merge_requests,则只有这些作业才会在管道中(如果它是合并请求管道)。其他工作将被排除在外。
这是文档中的示例:
build:
stage: build
script: ./build
only:
- main
test:
stage: test
script: ./test
only:
- merge_requests
deploy:
stage: deploy
script: ./deploy
only:
- main
Run Code Online (Sandbox Code Playgroud)
在此示例中,指定应为合并请求管道运行的唯一作业是 作业test。对于标准push管道,build和deploy作业将运行,但是当创建新的合并请求时,更改将被推送到作为现有合并请求的源分支的分支,或者您点击“管道”选项卡上的“运行管道”按钮以获取新的合并请求。合并请求,它将运行合并请求管道。
这是另一个具有不同场景的示例:
A:
stage: some_stage
only:
- branches
- tags
- merge_requests
script:
- script.sh
B:
stage: some_other_stage
only:
- branches
- tags
- merge_requests
script:
- script.sh
C:
stage: third_stage
only:
- merge_requests
script:
- script.sh
Run Code Online (Sandbox Code Playgroud)
在此示例中,作业A和B为所有管道类型push、tags、merge_requests等运行,但作业C仅针对管道运行merge_request。
这就是为什么你的test_without_only_policy工作永远不会在管道中test_with_only_policy运行。test_with_only_policy专门为合并请求事件运行,但test_without_only_policy不运行。
| 归档时间: |
|
| 查看次数: |
19007 次 |
| 最近记录: |