Azure DevOps - YAML 管道触发器在源完成之前启动 运行
Azure DevOps - YAML Pipeline Trigger starts run before completion of source
我有两条管道 - 一条用于 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'
一种方法是在 CI 的末尾创建一个标签,CD 可以被这个标签触发。
ADO CI 管道示例代码:
trigger:
- main
ADO CD 管道示例代码:
trigger:
tags:
include:
- v*
其中一种方法可能是在新版本发布时触发您的 CD 管道。因此,事件流可以这样发生:
- 主合并触发器 CI => 这将 运行 生成新版本的可选任务
- 版本发布时触发 CD 流水线
trigger:
tags:
include:
- v*
将 none 触发器添加到 CD 管道有效。感谢Rohit for the link to similar question -
# needed to add this trigger
trigger: none
resources:
pipelines:
- pipeline: cd
source: pipeline-trigger-ci
trigger:
branches:
include:
- refs/heads/develop
...
我有两条管道 - 一条用于 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'
一种方法是在 CI 的末尾创建一个标签,CD 可以被这个标签触发。
ADO CI 管道示例代码:
trigger:
- main
ADO CD 管道示例代码:
trigger:
tags:
include:
- v*
其中一种方法可能是在新版本发布时触发您的 CD 管道。因此,事件流可以这样发生:
- 主合并触发器 CI => 这将 运行 生成新版本的可选任务
- 版本发布时触发 CD 流水线
trigger:
tags:
include:
- v*
将 none 触发器添加到 CD 管道有效。感谢Rohit for the link to similar question -
# needed to add this trigger
trigger: none
resources:
pipelines:
- pipeline: cd
source: pipeline-trigger-ci
trigger:
branches:
include:
- refs/heads/develop
...