从另一个管道触发Azure Devops管道 [英] Triggering an Azure Devops pipeline from another pipeline

查看:200
本文介绍了从另一个管道触发Azure Devops管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从Azure DevOps的另一个管道触发管道时遇到问题.我有一个配置项管道,并且每当配置项在主分支上传递时,我都想触发一个部署管道.这似乎在技术上是可能的,但是

I'm having problems triggering a pipeline from another Pipeline in Azure DevOps. I have a CI pipeline and I want to trigger a Deploy Pipeline whenever CI passes on a master branch. This seems to be technically possible, but the documentation is unclear.

我看到以下内容:

# this is being defined in app-ci pipeline
resources:
  pipelines:
  - pipeline: securitylib
    source: security-lib-ci
    trigger: 
      branches:
      - releases/*
      - master

但是尚不清楚a)这是在触发管道(在我的情况下是CI管道)还是在触发管道(在我的情况下是部署管道)中进行.

But it's unclear as to a) whether this goes in the triggering pipeline (in my case the CI pipeline) or the triggered pipeline (in my case, the deploy pipeline).

还不清楚pipelinesource是指什么,以及如何找出这些变量?它们都是管道的名称吗?我尝试了各种不同的排列方式,但似乎没有任何效果.

It's also unclear as to what the pipeline and source refer to, and how I find out these variables? Are they both the name of the pipeline? I've tried various different permutations and nothing seems to be working.

推荐答案

如果您不是从触发管道发布工件,那么它将不会触发被触发的管道.

If you're not publishing an artifact from the triggering pipeline, it won't trigger the triggered pipeline.

此外,对这些类型的触发器的使用也有很大的限制.必须将depends管道中的defaultBranch for manual and scheduled builds更改为工作分支.否则,它将不会在source管道执行结束时启动.因此,假设您正在处理feature分支,并且defaultBranch设置为feature.您提交您的代码,一切将按预期运行:source管道开始运行,最后,depends管道将被触发.都好!但是,当您合并为master时,如果不更改defaultBranch,则depends管道不会在source管道的末尾触发.在答案的末尾,我将说明如何更改defaultBranch.

Also, there is a very big restriction on the use of these types of triggers. It is necessary to change the defaultBranch for manual and scheduled builds in the depends pipeline, to the working branch. Otherwise it won't kick in at the end of the source pipeline execution. So, let's say you're working on feature branch, and defaultBranch is set to feature. You commit your code, and everything will run as expected: the source pipeline kicks in, and at its end, the depends pipeline will be triggered. All good! But when you will merge into master, if you do not change the defaultBranch, the depends pipeline won't be triggered at the end of the source pipeline. I explain how to change the defaultBranch at the end of the answer.

我设法将其启动并在一个简约项目上运行. 此处,您可以获取代码并

I managed to get this up and running on a minimalistic project. Here you can have the code and here the project on Azure DevOps. I will try to guide you through how I did it, and answer the questions you've asked in your post.

我将触发管道称为depends管道,并将触发管道称为source管道.

I will be calling the triggered pipeline as depends pipeline and the triggering pipeline as source pipeline.

source管道上,无需执行任何操作,除非发布工件.如果您不从source管道发布工件,它将无法正常工作.在下面,您可以找到我在虚拟source管道中使用的代码.我希望为master分支触发它,最后,我想确保发布一个工件.

On the source pipeline, there's no need to do anything except publishing an artifact. If you don't publish an artifact from the source pipeline, it won't work. Below you can find the code I am using for my dummy source pipeline. I want it to be triggered for master branch, and at the end I want to be sure to publish an artifact.

trigger:
  branches:
    include: # branch names which will trigger a build
    - master
pr: none

steps:
  # required to cause pipeline triggering downstream
  - task: CopyFiles@2
    inputs:
      contents: $(System.DefaultWorkingDirectory)/**/*.yml
      targetFolder: $(Build.ArtifactStagingDirectory)
  - task: PublishBuildArtifacts@1
    inputs:
      pathtoPublish: $(Build.ArtifactStagingDirectory)
      artifactName: dummy-$(Build.BuildId)

depends管道(如下所示的代码)上,我必须禁用CIPR触发器,否则当我提交此仓库时,该管道将由CI触发器触发,然后在source管道的执行结束之前.这是通过我的代码的前两行完成的.然后我希望名为source的管道(这是下面的YAML中的source属性),在名为Pipelining的项目(YAML中的project属性)内将触发当前的(depends)管道当此更新master分支时.

On the depends pipeline (code shown below), I have to disable CI and PR triggers, otherwise when I commit to this repo, this pipeline will be triggered by the CI trigger, and then by the end of the execution of the source pipeline. This is done by the two first lines of my code. Then I want that the pipeline named source (this is the source property in the YAML below), within the project named Pipelining (project property in the YAML) will trigger the current (depends) pipeline when this updates master branch.

trigger: none
pr: none
resources:
  pipelines:
    - pipeline: source
      project: Pipelining
      source: source
      trigger: 
        branches:
          include:
          - master
steps:
  - checkout: none
  - script: echo 'triggered depends'

这有意义吗?重要的是,您的Azure DevOps上的项目名称必须与YAML depends管道代码中的property相匹配.对我来说,它是Pipelining

Does it make sense? It is important for your project name on Azure DevOps to match the property in the YAML depends pipeline code.For me it is Pipelining

以及source属性,同样在YAML depends管道代码中.

As well as the source property, again in the YAML depends pipeline code.

为了更改defaultBranch,由于上述问题,您应该编辑管道(在本例中为depends管道),然后在右上角的三个点上选择Triggers .然后选择YAML选项卡,您将进入下图所示的屏幕,您可以在其中设置工作分支.

In order to change the defaultBranch, because of the issue mentioned above, you should edit the pipeline (in this case, the depends pipeline), then on the three dots on the top right corner pick Triggers. Then choose the YAML tab, and you will get to the screen shown in the image below, where you can set the working branch.

这篇关于从另一个管道触发Azure Devops管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆