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://learn.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
3 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.

- 20,786
- 3
- 19
- 28
-
Thank you. Yes, the "Rerun stage" from the previous job is one option but i was wondering if there is any way to implement within the YAML (i'm using runOnce) to rollback to previous stage automatically if the deployment fails. – Ia1 May 29 '20 at 16:00
-
@iab. In `RunOnce` strategy , you could use `on : failure` or `on: success` to judge the results and implement the steps. If you want to run the `whole` previous successful build, you could add `Azure CLI` task and run the [script](https://learn.microsoft.com/en-us/cli/azure/ext/azure-devops/pipelines/build?view=azure-cli-latest). But if you only want to run single stage , it seems that manual operation is the most effective. Here is [a suggestion ticket](https://developercommunity.visualstudio.com/idea/884036/rerun-successful-stages-in-yaml-pipelines.html), it may help. – Kevin Lu-MSFT Jun 02 '20 at 01:59
-
Thanks @Kevin Lu-MSFT. I accepted the "manual rerun" option since at this point i don't have a clear direction as to what we would be rolling back (new to this process) but i think i will explore the RunOnce strategy more to get some idea about using it within the yaml. Do you have any examples? – Ia1 Jun 04 '20 at 18:26
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://learn.microsoft.com/en-us/azure/devops/pipelines/release/approvals/gates?view=azure-devops

- 347
- 1
- 10
The rerun stage seems ideal option for rollback and it is accurate on the run. Thanks to Retention policy of pipeline, in which we can retain specific runs that can be used for rollback anytime.
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 11 '23 at 08:05