我正在使用部署在内部的Azure DevOps Server。我想使用Azure DevOps Pipelines实现以下目标:
我无法在documentation中找到合适的任务来完成此任务。我想念什么吗?我可以编写自己的自定义任务来使管道等待外部信号吗?
答案 0 :(得分:1)
要启动管道,然后等待我的外部流程,我选择了阻力最小的路径,并将其编码为PowerShell Task。
外部过程通过REST API控制。通过POST请求完成启动,然后循环继续使用GET请求轮询API,以查看工作是否完成。如果经过了一定的时间却没有成功完成该过程,则循环中止并且任务失败。
这是我代码的要旨:
$TimeoutAfter = New-TimeSpan -Minutes 5
$WaitBetweenPolling = New-TimeSpan -Seconds 10
# Launch external process
Invoke-RestMethod ...
$Timeout = (Get-Date).Add($TimeoutAfter)
do
{
# Poll external process to see if it is done
$Result = Invoke-RestMethod ...
Start-Sleep -Seconds $WaitBetweenPolling.Seconds
}
while (($Result -eq "IN_PROGRESS") -and ((Get-Date) -lt $Timeout))
if ($Result -ne "SUCCESS")
{
exit 1
}
PS-最好在上面的代码中撒些有意义的Write-Host
消息,以使其在管道中运行时更易于调试。