5

I am using Azure DevOps Server deployed on premises. I would like to achieve the following, using Azure DevOps Pipelines:

  1. Pull, build and package a C# solution.
  2. Call out to a proprietary deployment server (deployed in the same network as ADOS) to pick up the package and deploy it to a target machine.
  3. Have the deployment server signal Azure DevOps that it's done deploying.
  4. Original (or dependent?) pipeline runs some tests against the newly deployed target.

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?

urig
  • 16,016
  • 26
  • 115
  • 184

1 Answers1

3

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 when running in the pipeline.

urig
  • 16,016
  • 26
  • 115
  • 184
  • 1
    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. – Hugh Lin Feb 05 '20 at 10:44
  • 1
    Clever to use a PowerShell Task. Any idea how to poll for more than the timeout limit for a job (https://learn.microsoft.com/en-us/azure/devops/pipelines/process/phases?tabs=yaml&view=azure-devops#timeouts)? – Michael Osofsky Dec 07 '21 at 17:33
  • @MichaelOsofsky thanks. I don't see how it would be possible to poll beyond the job timeout but maybe you don't need to do that - on a self-hosted agent the timeout can be removed. – urig Dec 09 '21 at 10:21
  • Would be interested in a solution for Azure-hosted agents not self-hosted. Somehow the [ManualValidation@0](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/manual-validation?view=tfs-2017&tabs=yaml) task allows a job to wait for several days. I wonder how it does that. – Michael Osofsky Dec 13 '21 at 23:49
  • @MichaelOsofsky did you read the link in my previous comment? It says that on a self-hosted agent you can disable the timeout with `timeoutInMinutes: 0`. To get full answers, I can suggest that you post this as a new question here on StackOverflow. :) – urig Dec 15 '21 at 06:53