【发布时间】:2021-02-18 22:06:16
【问题描述】:
我正在尝试基于构建完成触发器运行管道。启用了 4 个构建完成触发器。因此,管道运行了 4 次。
我已启用“在构建过程中进行批量更改”。
所有构建完成后如何让它运行一次?
【问题讨论】:
-
@LeoLiu-MSFT 我创建了结合 4 个的单个管道,以便在构建完成时只进行一次运行
标签: azure azure-devops azure-pipelines
我正在尝试基于构建完成触发器运行管道。启用了 4 个构建完成触发器。因此,管道运行了 4 次。
我已启用“在构建过程中进行批量更改”。
所有构建完成后如何让它运行一次?
【问题讨论】:
标签: azure azure-devops azure-pipelines
Batch changes while a build is in progress 仅适用于 CI 构建。您不能将其应用于构建完成触发器。但是,您可以使用 PowerShell 运行另一个管道:How to trigger a build from another build pipeline in azure devops
只需检查活动管道即可跳过许多触发器。这是一个例子:
$user = ""
$token = $env:SYSTEM_ACCESSTOKEN
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$orgUrl = "$env:SYSTEM_COLLECTIONURI"
$teamProject = "$env:SYSTEM_TEAMPROJECT"
$currentBuildDefId = "$env:SYSTEM_DEFINITIONID"
$buildBodyTemplate = "{`"definition`": {`"id`": <build_id>}}"
$restApiQueueBuild = "$orgUrl/$teamProject/_apis/build/builds?api-version=6.0"
$restApiGetBuilds = "$orgUrl/$teamProject/_apis/build/builds?definitions=$currentBuildDefId&statusFilter=inProgress,notStarted&api-version=6.0"
function InvokeGetRequest ($GetUrl)
{
return Invoke-RestMethod -Uri $GetUrl -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
}
function InvokePostRequest ($PostUrl, $body)
{
return Invoke-RestMethod -Uri $PostUrl -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $body
}
function RunBuild($buildId)
{
$buildBody = $buildBodyTemplate.Replace("<build_id>", $buildId)
Write-Host $buildBody
$buildresponse = InvokePostRequest $restApiQueueBuild $buildBody
Write-Host $buildresponse
}
$resBuild = InvokeGetRequest $restApiGetBuilds
if ($resBuild.count -gt 1)
{
Write-Host $resBuild.count " builds in progress, skip the second build"
return
}
RunBuild SECOND_BUILD_DEF_ID
【讨论】: