CI job 依赖另一个允许失败的 job,该如何编写 yaml
问题解答
使用 needs、dotenv 可以实现:
- Job1 成功时,执行 Job2;
- Job1 失败时,不执行 Job2;
unit-test-job:
allow_failure: true
stage: test
script:
- echo "Code coverage is 60%, it's too low!"
- exit 1
after_script:
- echo "CI_JOB_STATUS:""$CI_JOB_STATUS"
- echo "CI_JOB_STATUS_UNIT_TEST=$CI_JOB_STATUS" >> build.env
artifacts:
when: always
reports:
dotenv: build.env
visualize:
allow_failure: true
stage: test
image: registry.gitlab.com/haynes/jacoco2cobertura:1.0.9
before_script:
- echo "CI_JOB_STATUS_UNIT_TEST:""$CI_JOB_STATUS_UNIT_TEST"
- if [ "$CI_JOB_STATUS_UNIT_TEST" != "success" ]; then exit 1; fi
script:
- echo "convert jacoco.xml to cobertura.xml"
needs: ["unit-test-job"]
截图补充
Demo示例
参考资料
由 Zhou YANG 编辑于