Nivedha Chellam
Nivedha Chellam

Reputation: 13

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

I'm using the $releaseUri = "https://vsrm.dev.azure.com/{Org}/{Project}/_apis/Release/deployments?definitionId=$releaseDefinitionId&definitionEnvironmentId=$envId?api-version" rest api to determine release deployment status. The caveat here is that I'm doing this as a task in the release itself. Its always says the release is in progress. My aim is to tag the build only if the release gets succeeded. Wondering How could I'll be able to get the release status during the release before release completion.

Appreciating any inputs on this!

Upvotes: 1

Views: 2032

Answers (1)

Mengdi Liang
Mengdi Liang

Reputation: 18958

Its always says the release is in progress.

If you run this API as a task during the release, in progress is a expect behavior. Because for release pipeline server, it contains a lot of behaviors, in addition to the deployment jobs, it also includes approve, gate and etc. For the server, the release is the real end only after all behaviors ends. Or it will considered as in progress.

In your operation, you set this API as a part of release process, it will never get the real deployment status because the completed release process haven't finished.

Tag the build only if the release gets succeeded

To achieve what you want, there's no directly approach can help you achieve this. As workaround, you could create one release-level variable to help you do that.

Scenarios: There has a release pipeline which has a stage to execute the deployment job. What my work around logic is create a release-level variable with a new task at the last step of the agent job only after the previous tasks which in the same agent job are all succeed. Now, if the release-level variable created successfully, it would represent this agent job is ran successfully.

For the API of create variable in release, you could use:

PUT https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=5.0

And the completed script, you can refer to this blog script.


With this logic, one new release-level variable created means its corresponding agent job is succeed. So, no matter how many agent jobs exist in the release pipeline, just need to determine whether these variables exist, or whether the value is set as what you expect(such as true or false). If it is satisfied, then perform the operation of adding a tag to the build.

Add one agent job which would executed at the end of the release process. In this agent job, just need to add one task used to tag the build. Use condition expression in the agent job level to determine whether the task need to be executed.

Upvotes: 2

Related Questions