0
votes

In my Azure DevOps release pipeline I have a powershell script that sends a REST request to another application with the status 'failed' or 'successful'.

I want the status to send 'failed' if any of the previous jobs failed. So basically something like this:

if (($Agent  -eq "Succeeded") -and ($LastJobsFailed -ne "true")) {
   $change_status="successful"
}
else {
   $change_status="failed"
}

Now I know that Azure Devops uses this status somewhere, since you can specify whether a job starts or not based on the results of the last jobs.

As a workaround I copied my script twice one time with status "successful" and this only runs when all jobs succeed and vice versa. But i'd like to do everything in one script :)

so I would expect it would be possible to find a list with all previous job statuses or something. Anyone any ideas?

thanks!

1
How many stages (environments) do you have?Shayki Abramczyk
I'm not sure if this applies. Any exceptions from powershell commands are kept in a $error variable. It's actually an object array, with the latest exception in $error[0]. You have to pipe it to format-list -force to see all the properties.js2010
@ShaykiAbramczyk the use case here is that the logic runs in one staging environment which consists of several jobs. Kinda like below answer of Lu Mike.Jay05
@Jay05 If you have only 1 stage, you can add another stage with one task to check the first stage error/success.Shayki Abramczyk

1 Answers

1
votes

I think you don't need to to check the status of previous jobs in the powershell script. A workaround for that is, you can create one job(named jobSendOK) which sepecify the run condition as "Only when all previous jobs have succeed", and create another one job (named jobSendNG)which sepecify the run condition as "Only when a previous job has failed". In jobSendOK, add a powershell task for sending 'successful', while jobSendNG has a powershell task for sending 'failed'.

enter image description here