Concourse流水线报错:如何让pr_approver在ci_concourse_test_pr成功后运行?
问题描述
我正在搭建由Pull Request触发的Concourse流水线,流程是PR触发后运行测试,测试成功后执行脚本批准该PR。但用fly命令设置流水线时遇到错误:
invalid jobs: jobs.pr_approver.plan.do[0].get(pr_approver).passed: job 'ci_concourse_test_pr' does not interact with resource 'pr_approver'
当前流水线配置如下:
--- resource_types: - name: pull-request type: docker-image source: repository: teliaoss/github-pr-resource resources: - name: ci_concourse_test type: pull-request check_every: 168h webhook_token: {SECRET} source: repository: {GITHUB_REPO} access_token: {SECRET} v3_endpoint: https://api.github.com/ v4_endpoint: https://api.github.com/graphql - name: ci_concourse_test_main type: git source: branch: main uri: {GITHUB_REPO} private_key: {SECRET} - name: pr_approver type: git source: branch: main uri: {GITHUB_REPO} private_key: {SECRET} jobs: - name: ci_concourse_test_pr plan: - get: ci_concourse_test trigger: true - put: ci_concourse_test params: path: ci_concourse_test status: pending - task: sample-test config: platform: linux image_resource: type: docker-image source: repository: {DOCKER_REPO} tag: latest inputs: - name: ci_concourse_test run: path: python3 args: [ "ci_concourse_test/ci/test.py" ] on_success: put: ci_concourse_test params: path: ci_concourse_test status: success on_failure: put: ci_concourse_test params: path: ci_concourse_test status: failure # Attempting to approve the PR - name: pr_approver plan: - get: pr_approver passed: [ci_concourse_test_pr] trigger: true - task: pr_approver config: platform: linux image_resource: type: docker-image source: repository: {GITHUB_REPO} tag: latest inputs: - name: pr_approver run: path: python3 args: [ "github_interface/test.py" ]
问题原因与修复方案
错误根源是:pr_approver任务里用passed: [ci_concourse_test_pr]声明依赖,但ci_concourse_test_pr任务从未使用过pr_approver这个资源,Concourse不允许这种无关联的跨任务依赖。此外原配置还有缩进错误、资源冗余的问题,直接修改如下:
修改后的完整配置
--- resource_types: - name: pull-request type: docker-image source: repository: teliaoss/github-pr-resource resources: - name: ci_concourse_test type: pull-request check_every: 168h webhook_token: {SECRET} source: repository: {GITHUB_REPO} access_token: {SECRET} v3_endpoint: https://api.github.com/ v4_endpoint: https://api.github.com/graphql - name: ci_concourse_test_main type: git source: branch: main uri: {GITHUB_REPO} private_key: {SECRET} jobs: - name: ci_concourse_test_pr plan: - get: ci_concourse_test trigger: true - put: ci_concourse_test params: path: ci_concourse_test status: pending - task: sample-test config: platform: linux image_resource: type: docker-image source: repository: {DOCKER_REPO} tag: latest inputs: - name: ci_concourse_test run: path: python3 args: [ "ci_concourse_test/ci/test.py" ] on_success: put: ci_concourse_test params: path: ci_concourse_test status: success on_failure: put: ci_concourse_test params: path: ci_concourse_test status: failure # PR批准任务 - name: pr_approver plan: - get: ci_concourse_test passed: [ci_concourse_test_pr] trigger: true - task: pr_approver config: platform: linux image_resource: type: docker-image source: repository: {DOCKER_REPO} # 需使用包含Python、GitHub依赖的镜像,而非代码仓库 tag: latest inputs: - name: ci_concourse_test run: path: python3 args: [ "ci_concourse_test/github_interface/test.py" ] # 路径对应PR内脚本位置
关键修改点
- 删除冗余资源:去掉没用的
pr_approvergit资源,直接复用触发流水线的ci_concourse_test(pull-request类型资源),它包含PR的完整信息,足以用于批准操作 - 修正依赖规则:
pr_approver任务拉取ci_concourse_test并指定passed: [ci_concourse_test_pr],此时前序任务确实使用过该资源,符合Concourse的依赖逻辑 - 修复YAML缩进:确保
passed、trigger和get处于同级缩进,避免语法错误 - 修正镜像与路径:原配置里用代码仓库作为任务镜像的错误,改为使用包含运行环境的Docker镜像,同时调整脚本路径对应PR内的文件位置
内容的提问来源于stack exchange,提问作者xalexander
相关产品推荐
相关产品推荐

