如何定义GitLab CI作业使其可依赖两个前置构建作业的任意一个
问题原因
deploy作业报错的核心原因是dependencies配置项只能填写具体的作业名称,不支持直接填写阶段名称,你配置中填写的build是阶段名,不存在同名作业,因此GitLab无法识别。
解决方案
要让deploy作业可以自动获取build-incremental或build-nightly任意一个运行成功的作业产物,只需要将两个构建作业的名称都添加到dependencies列表中即可。
当流水线中只有其中一个构建作业运行时,GitLab会自动忽略未运行/已跳过的作业,仅拉取实际运行成功的构建作业的产物,完全匹配你的需求。
提示:如果后续配置触发规则保证同一流水线内仅会运行其中一个构建作业,不会出现两个构建作业同时执行的情况,就不会出现产物冲突覆盖的问题。
修改后的完整配置示例
stages: - build - deploy - test variables: BUILD_ARTIFACTS_DIR: "artifacts" build-incremental: timeout: 5h stage: build script: - echo "Building" - ./ci/do-prep - echo "done." artifacts: paths: - $BUILD_ARTIFACTS_DIR/ variables: BUILD_TOP_DIR: "/workspace/builds" tags: - yocto when: manual build-nightly: timeout: 5h stage: build script: - echo "Building" - ./ci/do-prep - echo "done." artifacts: paths: - $BUILD_ARTIFACTS_DIR/ tags: - yocto when: manual deploy: stage: deploy script: - echo "Deploying..." - ./ci/do-deploy - echo "done." tags: - yocto dependencies: - build-incremental - build-nightly when: manual test: stage: test script: - echo "Testing..." - ./ci/do-test - echo "done." tags: - yocto dependencies: - deploy when: manual
内容的提问来源于stack exchange,提问作者ZioByte
相关产品推荐
相关产品推荐

