需要从另一个管道调用多个管道:如何触发 ADO 管道的资源

时间:2021-07-02 10:39:12

标签: azure-devops azure-pipelines devops

我需要从另一个管道触发多个管道。为此,我在 YAML 中获得了 ADO 资源进行配置。资源是位于管道之外的管道使用的任何东西。

来源https://docs.microsoft.com/en-us/azure/devops/pipelines/process/resources?view=azure-devops&tabs=example#resources-builds

我遵循的步骤:

  1. 创建了一个 GIT 存储库并在其上创建了一个管道 yaml。这应该是一个只会触发其他管道的虚拟存储库。

那里的 yaml 是:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- none


resources:
  pipelines:
    - pipeline: 02-understanding-stages-pipeline
      project: azure-devops-kubernetes-terraform
      branch: master
      source: 02-understanding-stages-pipeline
      trigger:
        branches:
          - master
        stages:
          - Build
          - DevDeploy

YAML 错误

An error occurred while loading the YAML build pipeline. The array must contain at l 
least one element. Parameter name: stages

02-understanding-stages-pipeline 是另一个项目中的另一个管道。我需要从这个管道触发和设置其他这样的管道。

问题:

  1. 关于如何从其他管道触发管道的建议
  2. 知道如何解决我遇到的错误
  3. 管道下的管道是什么?能简单解释一下吗?

提前致谢!!

1 个答案:

答案 0 :(得分:1)

<块引用>

关于如何从其他管道触发管道的建议

您可以使用 Trigger Build Task extension 如下:

- task: TriggerBuild@3
displayName: 'Trigger a new build of Validate-BuildVariable Update'
inputs:
    buildDefinition: 'Your build name'
    useSameBranch: false
    branchToUse: master
    waitForQueuedBuildsToFinish: true
    authenticationMethod: 'OAuth Token'
    password: $(System.AccessToken)

Rest API

POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1

<块引用>

知道如何解决我得到的错误

我做了一个测试,这对我有用:

trigger: none


resources:
  pipelines:
    - pipeline: pipelineUnderstanding
      branch: master
      source: kmadof.dm-so-47-multi-stage
      trigger:
        branches:
          - master
        stages:
          - Build
          - Deploy
steps:
- script: echo 'siema'

如果您的管道与您在这里写的完全一样,我建议您检查您的阶段。

<块引用>

管道下的源和管道是什么?能简单解释一下吗?

来源是

<块引用>

产生工件的管道名称

管道是

<块引用>

管道资源变量中使用的资源标识符

它只是资源对象的别名。请检查here