You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Concourse CI单仓库流水线:如何实现测试通过后触发特定部署

解决方案

方案一:复用同一Git资源,添加路径过滤与测试依赖(推荐)

直接在set-pipeline-1的repo-self资源获取步骤中,同时添加paths过滤和passed依赖,无需额外定义repo-self-pipeline-1资源。这样既保证只有指定路径变更时触发部署,又强制等待全仓测试完成。

修改后的完整配置:

resources:
  - name: "repo-self"
    type: git
    source:
      uri: "git@github.com:some-repo.git"
      branch: main

jobs:
  - name: testing
    plan:
      - get: "repo-self"
        trigger: true
      - in_parallel:
          - task: "test-1"
          - task: "test-2"
          - task: "test-3"
  - name: "set-pipeline-1"
    plan:
      - get: "repo-self"
        passed:
          - testing
        trigger: true
        paths:
          - "concourse/pipeline-1/*"
      - set_pipeline: "pipeline-1"
        file: "repo-self/concourse/pipeline-1/main.yaml"

原理说明

  • paths: ["concourse/pipeline-1/*"]:仅当指定路径下的文件变更时,才会触发该job的执行。
  • passed: ["testing"]:强制要求该步骤获取的repo-self版本必须已经通过testing job的验证,确保全仓测试完成后才会部署流水线。
  • 复用同一Git资源,避免了多资源版本不一致的问题,也无需重复执行测试。

方案二:锁定多Git资源的SHA版本(适配原有多资源结构)

如果必须保留repo-self-pipeline-1资源,可以通过Concourse的版本引用语法,将其版本锁定到repo-self(已通过测试)的SHA上,确保两者代码版本完全一致。

修改后的set-pipeline-1 job配置:

jobs:
  - name: "set-pipeline-1"
    plan:
      - get: "repo-self"
        passed:
          - testing
      - get: "repo-self-pipeline-1"
        trigger: true
        # 强制使用测试通过的repo-self的SHA版本
        version:
          ref: ((repo-self.version.ref))
      - set_pipeline: "pipeline-1"
        file: "repo-self-pipeline-1/concourse/pipeline-1/main.yaml"

原理说明

  • ((repo-self.version.ref)):引用repo-self资源获取到的commit SHA,强制repo-self-pipeline-1拉取完全相同版本的代码。
  • repo-self的passed: ["testing"]确保只有测试通过的版本才会进入后续步骤,避免未测试的代码被部署。
  • 保留repo-self-pipeline-1的trigger: true,仅当指定路径变更时触发job,但触发后会等待对应版本通过测试才会执行部署。

内容的提问来源于stack exchange,提问作者Robert F.P. Ludwick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 02:18:16