向GitLabCIyaml添加需要关系但出现错误:作业未添加到管道中
我正在尝试在 Gitlab CI yaml 配置文件中的作业之间添加需求。
stages:
- build
- test
- package
- deploy
maven-build:
stage: build
only:
- merge_requests
- master
- branches
...
test:
stage: test
needs: [ "maven-build" ]
only:
- merge_requests
- master
...
docker-build:
stage: package
needs: [ "test" ]
only:
- master
...
deploy-stage:
stage: deploy
needs: [ "docker-build" ]
only:
- master
...
deploy-prod:
stage: deploy
needs: [ "docker-build" ]
only:
- master
when: manual
...
我已经使用 GitLab CI 在线 lint 工具来检查我的语法,它是正确的。
但是当我推送代码时,它总是抱怨:
'test' job needs 'maven-build' job
but it was not added to the pipeline
You can also test your .gitlab-ci.yml in CI Lint
GitLab CI 根本没有运行。
更新:我终于做到了。我认为这个needs位置很敏感,needs在 下全部移动stage,它起作用了。我的原始脚本在它们之间包含了一些其他配置。
回答
相互依赖的 CI 作业需要具有相同的限制!
在您的情况下,这意味着共享相同的only目标:
stages:
- build
- test
maven-build:
stage: build
only:
- merge_requests
- master
- branches
test:
stage: test
needs: [ "maven-build" ]
only:
- merge_requests
- master
- branches
根据我的经验,这应该有效^^