GitLab CI跨分支获取工件报错:如何在其他分支使用develop分支工件?
解决GitLab CI跨分支引用工件的needs语法错误
问题根源
你要跨分支(develop)拉取snapshots job的工件,但needs指令里缺了必填的project字段——哪怕是当前项目,GitLab也要求明确指定这个字段,不然就会抛出jobs:test:needs:need project should be a string的错误。
修正后的完整配置
snapshots: stage: snapshot dependencies: - build script: - yarn test:ci-update artifacts: paths: - 'test/integration/snapshots/*.png' expire_in: 4 week only: - develop test: stage: test dependencies: - build - snapshots script: - ls -lha test/integration/snapshots/reviewed-visual* - find test/integration/snapshots | grep reviewed-visual - yarn test:ci artifacts: paths: - test/integration/diffs/ - dist/test/ when: always needs: - project: ${CI_PROJECT_PATH} job: snapshots ref: develop artifacts: true
核心说明
${CI_PROJECT_PATH}是GitLab的预定义变量,会自动填充当前项目的路径,不用硬写项目名,配置更灵活。- 得保证develop分支的snapshots job已经成功跑完并生成了工件,不然test job会因为找不到工件报错。
- 保留
dependencies是为了明确依赖关系,不过GitLab会优先按照needs的规则拉取工件。
内容的提问来源于stack exchange,提问作者Martin
相关产品推荐
相关产品推荐

