0

我有两条管道——一条用于 CI,另一条用于 CD。想要在 CI 流水线完全完成后触发 CD 流水线。设置触发器(通过 YAML)后,我的两个管道一起触发,因此 CD 甚至在 CI 完成之前就完成了。

只有在 CI 完成后,我才能触发 CD 管道?

我的 CI 管道如下:

pr:
  - develop
trigger:
  - develop


resources:
- repo: self

variables:
  tag: '$(Build.BuildId)'

stages:
- stage: Build
  displayName: Build image
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: ubuntu-latest
    steps:
    - task: Docker@2
      displayName: Build an image
      inputs:
        command: build
        dockerfile: '$(Build.SourcesDirectory)/dockerfile'
        tags: |
          $(tag)
    
- stage: Push
  displayName: Push to Reg
  condition: and(succeeded(), in(variables['Build.SourceBranch'], 'refs/heads/develop'))
  jobs:
    - job: push
      steps:
      - task: Bash@3
        inputs:x
          targetType: 'inline'
          scriptx: 'echo "this is the push to reg task"'

我的 CD 管道如下:

resources:
  pipelines:
  - pipeline: cd
    source: pipeline-trigger-ci
    trigger:
      branches:
        include:
        - refs/heads/develop

pool:
  vmImage: ubuntu-latest

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'

4

3 回答 3

1

一种方法是在 CI 的末尾创建一个标签,并且 CD 可以由该标签触发。

ADO CI 管道示例代码:

trigger:
  - main

ADO CD 管道示例代码:

trigger:
  tags:
    include:
      - v*
于 2021-06-07T10:18:12.643 回答
1

其中一种方法可能是在新版本发布时触发您的 CD 管道。因此,事件流可以这样发生:

  • 主合并触发 CI => 它将运行生成新版本的可选任务
  • 发布版本时触发 CD 管道
trigger:
  tags:
    include:
      - v*
于 2021-06-07T10:24:18.957 回答
0

将 none 触发器添加到 CD 管道有效。感谢Rohit提供类似问题的链接 - Azure Pipeline to trigger Pipeline using YAML

# needed to add this trigger
trigger: none

resources:
  pipelines:
  - pipeline: cd
    source: pipeline-trigger-ci
    trigger:
      branches:
        include:
        - refs/heads/develop
...
于 2021-06-07T10:55:38.823 回答