以下是.gitlab-ci.yml
的示例:
---
stages:
- .pre
- test
- build
compile-build-pipeline:
stage: .pre
script: [...]
artifacts:
paths: [".artifacts/build.yaml"]
lint-source:
stage: .pre
script: [...]
run-tests:
stage: test
rules:
- if: '$CI_COMMIT_BRANCH == "$CI_DEFAULT_BRANCH"'
trigger:
strategy: depend
include:
artifact: .artifacts/tests.yaml
job: "compile-test-pipeline"
needs: ["compile-test-pipeline"]
build-things:
stage: test
rules:
- if: '$CI_COMMIT_BRANCH == "$CI_DEFAULT_BRANCH"'
trigger:
strategy: depend
include:
artifact: .artifacts/build.yaml
job: "compile-build-pipeline"
needs: ["compile-build-pipeline"]
...
这个配置应该始终运行(任何分支,任何来源)。测试和构建作业应仅在默认分支上运行。
然而,合并请求不执行作业,在除默认分支之外的分支手动触发管道会给出错误No Jobs/Stages for this Pipeline
。
我尝试在.pre
阶段的作业中明确设置一个始终运行的规则,使用rules: [{if: '$CI_PIPELINE_SOURCE'}]
,但没有成功。
我哪里做错了?
.pre
中的作业被添加,那么test
和build
呢?为什么它们不被视为独立于.pre
的单独阶段? - Arthur AttoutCI_COMMIT_BRANCH
不是默认分支(与相关作业的规则要求不同);因此它们未被添加到流水线中。这导致除了.pre
和.post
阶段中的作业之外,没有其他作业被添加。 - deepbrook