如何从外部将参数传递给Azure Dev ops构建管道以控制任务执行? [英] How to pass parameters to azure Dev ops build pipeline externally to control the tasks execution?

查看:118
本文介绍了如何从外部将参数传递给Azure Dev ops构建管道以控制任务执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的查询是 如何从外部将参数传递给Azure Dev ops构建管道以控制任务执行? 为了在这里详细解释,解释:

my query is How to pass parameters to azure Dev ops build pipeline externally to control the tasks execution? To explain in detail heres the explanation:

我在Azure Dev ops中有一个项目,该项目的构建管道配置了一系列任务,涉及构建解决方案,生成可部署的程序包等.通常,此过程执行得很好,没有任何问题.

I have a project in the azure Dev ops which has a build pipeline configured with some series of tasks involving building the solution, generating deployable package and etc. Usually this is getting executed well and good without any issues.

我要实现的是在此项目构建定义中声明一个管道变量,当我说它是某种完全不同的事物或诸如ms flow这样的外部应用程序时,可以从外部访问它,以便我可以将值传递给新创建如上所述的管道变量,并使用存储在此新变量中的该值,我应该能够跳过构建管道中的几个步骤,并且我应该只能执行几个步骤.

What I want to achieve is declare a pipeline variable in this project build definition that I can access externally when I say it is some thing like an altogether different or External application like ms flow so that I can pass a value to the newly created pipeline variable as stated above and using this value stored in this new variable I should be able to skip few steps in the build pipeline andi should be able to execute only few steps.

让我用一个例子来解释:

Let me explain with an example:

  1. 在azure Dev ops中考虑一个名为A的项目,该项目的构建管道配置了5个不同的任务
  2. 在同一构建管道中,假设创建了一个新管道变量,称为flag
  3. 考虑一个类似于ms flow的外部应用程序,该应用程序将在步骤1中触发项目A构建管道.
  4. 我应该能够使用第3步中的流程将值传递给在第2步中创建的标志变量,如true或false.
  5. 使用从ms流传递到构建管道的标志值,应执行构建管道中的任务,即,如果通过外部应用程序到达构建管道的值是true,则它应仅在构建中执行3、4个任务流水线并跳过其他错误,应在Azure开发运营中执行构建流水线中的所有步骤.

查询是如何实现或使这种行为发生?

The query is how to achieve or make this kind of behaviour to happen?

请帮我解决这个问题?

Please help me out in solving this issue?

如果无法将值传递给变量,您能否让我知道如何在从外部应用程序(如ms flow)触发的Azure开发操作构建管道中实现跳过行为?

If passing the value to variable is not possible, can you please let me know how to achieve the skipping behaviour in azure Dev ops build pipeline triggered from external application like ms flow?

推荐答案

由于有一个REST API可以在构建队列时传递参数,并且您可以在构建管道中指定自定义条件,因此有一种解决方法. 根据REST API文档,您可以将其转换为Powershell脚本,如下所示.

Since there is a REST API can pass parameters when queue a build and you can specify custom conditions in your build pipeline, there is a workaround. According to the REST API documentation, you can convert it to Powershell script like below.

Param(
       [string]$collectionurl = "https://dev.azure.com/{orgname}",
       [string]$project = "{projectname}",
       [string]$user = "{useraccount}",
       [string]$token = "{yourPAT}"
)

$base64AuthInfo= [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $token)))

$defurl = "$collectionurl/$project/_apis/build/builds?api-version=5.0"
$json = '{"parameters":  "{\"AnotherParameter\":  \"true\"}","definition":  {"id":  "{definitionId}"}}'
$updatedef = Invoke-RestMethod -Uri $defurl -Method Post -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

您可以创建三个构建管道.第一条管道是您的主要管道,其中有5个不同的任务.您可以如下设置自定义条件.这意味着,只有当AnotherParameter的值为true时,任务才会运行.

You can create three build pipelines. The first pipeline is your main pipeline which has 5 different tasks. You can set the custom condition like below. It means, only when the value of AnotherParameter is true, the task will run.

第二个管道和第三个管道是触发管道.在第二个管道中,可以使用powershell脚本将AnotherParameter设置为false,在第三个管道中,将该值设置为true.

The second pipeline and the third pipeline is the trigger pipeline. In the second pipeline, you can use powershell script to set the AnotherParameter as false and in the third pipeline, set the value as true.

然后设置第二条管道是由外部应用程序触发的,而第三条管道是由您的仓库或其他人触发的.

Then set the second pipeline is triggered by external application and the third pipeline is triggered by your repo or others.

当外部应用程序触发了第二个管道时,AnotherParameter的值将为false,并且第一个管道中的某些任务将不会运行.

When the external application triggered the second pipeline, the value of AnotherParameter will be false and some of tasks in the first pipeline will not run.

当您的提交触发了第三个管道时,AnotherParameter的值将为true,并且第一个管道中的所有任务将按预期运行.

When the third pipeline is triggered by your commit, the value of AnotherParameter will be true and all of task in the first pipeline will run as expected.

这篇关于如何从外部将参数传递给Azure Dev ops构建管道以控制任务执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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