norsk
norsk

Reputation: 55

How to get status of the release (success, failure) with powershell using Azure DevOps Rest API

I am using post method to create release in Azure DevOps:

$url = "https://vsrm.dev.azure.com/"+$organization+"/"+$project+"/_apis/release/releases?api-version=5.1" $body = @{definitionId = 9} | ConvertTo-Json -Depth 4 Invoke-RestMethod -Uri $url -Method POST -Body $body -ContentType "application/json" -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)}

My pipeline is simple with single stage which executes automatically. Release creation and execution works fine.

But how to get status of my stage/s using powershell and REST API. I need to keep executing script while Release is in progress and initiate script failure if any of the stages fails.

Any ideas?

Upvotes: 2

Views: 816

Answers (1)

Fairoz
Fairoz

Reputation: 878

Using DefinitionID and EnvironmentIDs (you will get this from your initial POST response), you can query the last release and check for "deploymentStatus" value in intervals and exit when the status changes to "succeeded/failed/cancelled".

(collectionURL)/(teamproject)/_apis/Release/deployments?definitionId="+RELEASE_DEFINITIONID+"&definitionEnvironmentId="+RELEASE_DEFINITIONENVIRONMENTID?api-version=1.0

enter image description here

Upvotes: 2

Related Questions