If the current release has failed and how to run the previous successful release automatically?
Ex: If A(Current release) has failed then automatically trigger B(Previous success release) release. Trigger from another release definition.
If the current release has failed and how to run the previous successful release automatically?
Ex: If A(Current release) has failed then automatically trigger B(Previous success release) release. Trigger from another release definition.
There is no easy way to achieve this and you need to use REST API.
GET https://vsrm.dev.azure.com/{{organization}}/{{project}}/_apis/release/deployments?definitionId=7&api-version=6.1-preview.2
You need to parse response in powershell to get your release id and other details.
POST https://vsrm.dev.azure.com/fabrikam/MyFirstProject/_apis/release/releases?api-version=6.0
Here is an example body
{
"definitionId": 1,
"description": "Creating Sample release",
"artifacts": [
{
"alias": "Fabrikam.CI",
"instanceReference": {
"id": "2",
"name": null
}
}
],
"isDraft": false,
"reason": "none",
"manualEnvironments": null
}
Details of artifacts you will find in response of first endpoint.
Here is an example how you may call REST API from task
$uri = "https://dev.azure.com/thecodemanual/DevOps Manual/_apis/build/builds/$(Build.BuildId)/timeline?api-version=5.1"
Write-Host $uri
# Invoke the REST call
$build = Invoke-RestMethod -Uri $uri -Method Get -Headers @{Authorization = "Bearer $(System.AccessToken)"} -ContentType "application/json"
$taskResult = $build.records | Where-Object {$_.name -eq "ConditionalStep" } | Select-Object result
Write-Host $taskResult.result
No need to be so complicated to use powershell to call api. We have built-in feature can achieve your requirement. Since release pipeline consists of one or more stages,re-deploy release pipeline can be considered as re-running stages.
So open the release pipeline definition first. Then navigate to Post-deployment conditions of the stage => Enable Auto-redeploy trigger => Select the Event and the action:
See the actual execution result:
This is the advantage of the Azure Devops so that you don't need to worry if some thing goes wrong during the Prod deployments as the tool will automatically reverse the last successful deployment by its own.
Updated: