I am using Azure DevOps Server deployed on premises. I would like to achieve the following, using Azure DevOps Pipelines:
I've not been able to find a suitable task in the documentation to get this done. Am I missing something? Can I write a custom task of my own to make the Pipeline wait for an external signal?
To make the Pipeline launch and then wait for my external process, I chose the path of least resistance and coded it as a PowerShell Task.
The external process is controlled through a REST API. Launching is done via a POST request and then a loop keeps polling the API with a GET request to see if the work is done. If a certain amount of time has passed without the process finishing successfully, the loop is aborted and the task is failed.
Here's the gist of my code:
$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 - It's a good idea to sprinkle meaningful Write-Host
messages in the above code, to make it easier to debug it when running in the pipeline.
Thanks for sharing your solution here, would you please accept your solution as the answer? So it would be helpful for other members who get the same issue to find the solution easily.