Auto Redeploy Last Successful Release on Failure - AzureDevOps
Today we’ll discuss a very important aspect of release pipelines which can save a lot of your time and effort incase you have to redeploy to the old release upon failure in the current release.
Suppose you are working on a very important project where you are spinning up an environment with the help of terraform scripts or you are deploying a crucial application that interacts with an API and shows you various results related to your project. And during deployment, something breaks and you end up having a deployment failure. Since the application is mission critical, you are tasked to deploy the last successful release immediately so that your clients don’t have to suffer. You deploy the last successful release by finding it in the AzureDevOps portal and your work is done for now.
The product is in development and a new release is released every week with a few hotfixes in the middle of the week. Everything was working fine, till your Senior Developer decided to go on a 2 months leave and now the junior staff breaks the release every now and then. You are tasked each time to deploy the last release and it’s becoming cumbersome for you and the project management team since this causes the application to be down due to your dependency to redeploy last successful release. Your project manager reached out to you and asked if you could automate this scenario as it’s too much time consuming and has dependency involved.
The solution to the above problem is hidden in the post deployment conditions of your release stage.
- Go to your release pipeline and click on post deployment conditions of your release stage.
2. Now enable the option for Auto-redeploy trigger.
3. Upon enabling, select the event “Deployment to this stage fails” and action “Redeploy the last successful deployment”.
4. Save your release configuration.
Now, your auto redeployment trigger is successfully configured and now it’s time to test!
- Lets deploy our release (the successful one)
2. Now make some changes in your pipeline to fail it intentionally, so that we can test our logic or simply send your breaking code for release.
Now as expected your release would break since we send a breaking code for deployment.
The release broke, but what automatically happened is, your last successful release automatically got queued for deployment upon your current release failure.
You may see the above screenshot which suggests our last successful release getting redeployed!
You can even check and find a deployment attempt triggered for the last successful release by going into your deployment stage of last successful release.
And that’s it!! Our goal is achieved and we have set an automatic trigger to redeploy last successful release on PROD if the current release fails! Your dependency and time consumed to manually search and manually trigger the successful release is removed and now we have a happy team and happy clients!
I hope my this blog helps you!
Please share with your colleagues or friends who might find this information useful!