如何触发依赖于 CI 管道的 CD 管道成功?

时间:2021-03-05 20:28:31

标签: azure-devops continuous-integration yaml continuous-delivery

我想要:

  • PipelineA 在成功完成后构建并上传工件
  • PipelineB 运行并下载 PipelineA 的工件

PipelineA 的触发器:

trigger:   
    branches:
        include:
        - release/*
        - master  

这按预期工作,只要更改代码,PipelineA 就会运行并构建工件。

PipelineB 的触发器(不起作用!)

trigger: none # important! we do not want to be deploying to environments without an artifact

resources: 
    pipelines:
    - pipeline: PipelineALocal # does not matter, only for pulling down local vars
      source: PipelineA # the exact name defined in ADO
      trigger: true # tried every variant under the sun to get this working but this pipeline will never run

我尝试了各种触发器组合,包括(显然应该始终有效 trigger: true?),但没有任何效果。管道永远不会触发。

resources.pipelines.branches.include 下,我尝试过:refs/heads/mastermasterrefs/heads/release/*release/* 以及介于两者之间的所有内容。当然,使用正确的 YAML 格式。

https://en.cppreference.com/w/cpp/language/implicit_conversion#Temporary_materialization 非常令人困惑,但我设法弄清楚如何从管道别名中获取 runID

--

我已经尝试通过触发器 UI 并成功配置基于 PipelineA 的 PipelineB Build 完成触发器。

这仅适用于 master 分支,因此我无法使用 variables['Build.SourceBranch'] 来确定这是暂存版本还是发布版本。

如何触发依赖于 CI 管道成功的 CD 管道?

1 个答案:

答案 0 :(得分:0)

这些管道有分离的情况吗?

我只使用一个 yml 用于 CI 和 CD 使用阶段,并依赖于 CI 阶段的成功:


stages:
- stage: CI
  jobs:
  - job:
    ...

- stage: CD
  dependsOn: CI
  jobs:
  - job:
    ...

编辑 2:

我试过了

trigger: none

resources: 
    pipelines:
    - pipeline: cd-test
      source: ci-pipeline
      trigger: true

在我的项目中,这工作正常,但您必须记住,当我从 {{1} 中删除它们时,PipelineB 中的触发器(在我的情况下为 ci-pipeline)必须在 master 分支上}}它停止工作了。


编辑 1:

要从另一个管道启用触发,您必须转到 master -> Edit Pipeline definition enter image description here

并设置触发器: enter image description here