I have a multi-stage pipeline YAML deploying to different environments (PreDev-Dev-QA-Stage-Prod) and i'm trying to implement rollback strategy to rollback to previous version or previous build artifact and was looking at this page https://docs.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops but couldn't figure out and also didn't find any examples. Any help is appreciated
2 Answers
According to the doc:
We currently only support the runOnce, rolling, and the canary strategies.
The rollback strategy doesn't seem to support in Yaml definition.
But you can manually run the previous stage again. Then the pipeline could rollback to the previous version.
Step1: Navigate to the build summary page of the previous build.
Step2: Select the stage and use "Rerun Stage" optiom.
Hope this helps.
What about adding an additional stage, which could be called Rollback.
This stage could use Kubectl to do a rollback:
kubectl rollout undo deployment/$DEPLOYMENT
To avoid having the stage run every time just add a manual approval or you could add a gate that checks if the deployment was successful, with a health check call, or checking for monitoring alerts, or by running integration tests.
https://docs.microsoft.com/en-us/azure/devops/pipelines/release/approvals/gates?view=azure-devops