我一直在寻找天蓝色的触发器documentation,但仍然找不到合适的解决方案。 在执行管道1的过程中,如何触发管道2,等待其成功完成或失败,并根据管道2的结果继续执行管道1或失败?
答案 0 :(得分:2)
在执行流水线1的过程中,如何触发流水线2,等待其成功完成或失败,并根据流水线2的结果继续执行流水线1还是失败?
一个接一个地触发管道,它会在触发管道成功完成后运行您的管道。在执行管线1时,我们不能使用它来触发管线1。
一种解决方法:
a。我们可以添加任务强大的外壳程序并添加脚本来调用REST API以使构建排队。
$connectionToken="PAT"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$PipelineUrl = "https://dev.azure.com/{Org name}/{project name}/_apis/pipelines/{Pipeline ID}/runs?api-version=6.0-preview.1"
$body ="{
`"resources`":{
`"repositories`":{
`"self`":{`"refName`":`"refs/heads/master`"
}
}
}
}"
$Pipelines = Invoke-RestMethod -Uri $PipelineUrl -ContentType "application/json" -Body $body -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST
b。添加任务电源外壳并输入代码Start-Sleep -Seconds 1000
来休眠管道1
c。将任务电源外壳添加到管道1中,以通过REST API,获得管道2的构建结果,并将结果设置为env变量。
d。在下一个任务中配置condition,以检查环境变量值。如果值为succeeded
,请继续运行管道1
答案 1 :(得分:0)
您可能正在寻找类似的东西。
# this is being defined in app-ci pipeline
resources:
pipelines:
- pipeline: securitylib # Name of the pipeline resource
source: security-lib-ci # Name of the pipeline referenced by the pipeline resource
trigger:
branches:
- releases/*
- master
它就在链接中,您已经链接了,但是在文档的同级部分中。我很惊讶您错过了它。
答案 2 :(得分:0)
这是我基于上述建议的解决方案:
- task: PowerShell@2
displayName: Running second pipeline
inputs:
targetType: 'inline'
script: |
Write-Host "Triggering pipeline..."
$connectionToken= "$(PAT)"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$PipelineUrl = "https://dev.azure.com/YourOrganization/yourProject/_apis/pipelines/${{ parameters.pipelineId }}/runs?api-version=6.0-preview.1"
Write-Host "Pipeline url: $PipelineUrl"
$body ="{
`"resources`":{
`"repositories`":{
`"self`":{`"refName`":`"refs/heads/${{ parameters.branch }}`"
}
}
}
}"
$response = Invoke-RestMethod -Uri $PipelineUrl -ContentType "application/json" -Body $body -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST
Write-Host "Response: $response"
$BuildUrl = "https://dev.azure.com/YourOrganization/yourProject/_apis/build/builds/$($response.Id)?api-version=6.1-preview.6"
Write-Host $BuildUrl
$TimeoutAfter = New-TimeSpan -Minutes 15
$WaitBetweenPolling = New-TimeSpan -Seconds 10
$Timeout = (Get-Date).Add($TimeoutAfter)
do
{
$Response = Invoke-RestMethod -Uri $BuildUrl -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Write-Host $Response.status
Start-Sleep -Seconds $WaitBetweenPolling.Seconds
}
while ((($Response.status -eq "notStarted") -or ($Response.status -eq "inProgress")) -and ((Get-Date) -lt $Timeout))
if ($Response.result -ne "succeeded")
{
Write-Host $Response.result
exit 1
}
管道 ID 的参数:pipelineId: $(resources.pipeline.resource.pipelineId)