I’ve got an Azure devops pipleine that runs a powershell script which – in turn – calls a number of other powershell scripts. One of the functions it calls uses Start-Process to make a call to MSDeploy to move releases onto Azure app services.
This generally works fine but occasionally stalls as we lose connection to the app service mid-deployment. I’m handling this by examining process handle on completion and – if it’s non-zero – I will retry the operation again up to 3 times. Working like this has always ensured the deploy completes successfully.
Despite managing this failure locally, the parent stage in the pipeline always interprets this as an error and will refuse to move on to the next stage. Does anyone know how I can call Start-Process in a way that will allow me to check if it worked like this WITHOUT killing the piepline? I don’t want to flag the stage to ignore any errors received in case there is a genuine breakdown in connectivity I couldn’t overcome.
See the function below. Checking the value of $proc.Handle is a reliable way of determining if it completed or not, but I can’t stop the error bubbling up to the stage when it happens.
function DeployService([string]$ServiceName, [array]$msdeployArgs) {
[int]$i=1
[bool]$Succeeded = $false
Write-Host("Deploying service [{0}] now..." -f $ServiceName)
for(;$i -le 3;$i++)
{
$proc = Start-Process $WebDeployFilePath -NoNewWindow -Wait -ArgumentList $msdeployArgs -PassThru
$handle = $proc.Handle
$proc.WaitForExit();
if ($proc.ExitCode -eq 0) {
$Succeeded = $true
break
} else {
Write-Host("Deployment of [{0}] failed with exit code [{1}], will retry up to 3 times" -f $ServiceName, $proc.ExitCode)
if ($i -lt 3) {
$Error.Clear()
Start-Sleep -Seconds 5
}
}
}
return $Succeeded
}
The parent stage carries on to completion, but the Powershell task is flagged as errored, so the next stage isn’t called.
Jonah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.