If a pipeline execution fails, you can use rollback to return your environment to a previously stable state. To use rollback, plan a rollback flow and understand how to implement it.
A rollback flow prescribes the steps required to reverse a failure in deployment. The flow takes the form of a rollback pipeline that includes one or more sequential tasks which vary depending on the type of deployment that executed and failed. For example, the deployment and rollback of a traditional application is different from the deployment and rollback of a container application.
- Clean up states or environments.
- Run a user-specified script to revert changes.
- Deploy a previous revision of a deployment.
To add rollback to an existing deployment pipeline, you attach the rollback pipeline to the tasks or stages in the deployment pipeline that you want to roll back before you run your deployment pipeline.
How do I configure rollback
To configure rollback in your deployment, you need to:
- Create a deployment pipeline.
- Identify potential failure points in the deployment pipeline that will trigger rollback so that you can attach your rollback pipeline. For example, you might attach your rollback pipeline to a condition or poll task type in the deployment pipeline that checks whether a previous task completed successfully. For information on condition tasks, see How do I use variable bindings in a condition task to run or stop a pipeline in Code Stream.
- Determine the scope of failure that will trigger the rollback pipeline such as a task or stage failure. You can also attach rollback to a stage.
- Decide what rollback task or tasks to execute in the event of a failure. You'll create your rollback pipeline with those tasks.
You can manually create a rollback pipeline, or Code Stream can create one for you.
- Using a blank canvas, you can manually create a rollback pipeline that follows a flow in parallel to an existing deployment pipeline. Then you attach the rollback pipeline to one or more tasks in the deployment pipeline that trigger rollback on failure.
- Using a smart pipeline template, you can configure a deployment pipeline with the rollback action. Then, Code Stream automatically creates one or more default rollback pipelines with predefined tasks that roll back the deployment on failure.
For a detailed example on how to configure a CD pipeline with rollback by using a smart pipeline template, see How do I roll back my deployment in Code Stream.
What happens if my deployment pipeline has multiple tasks or stages with rollback
If you add rollback to... | When does roll back occur... |
---|---|
Parallel tasks | If one of the parallel tasks fails, roll back for that task occurs after all the parallel tasks have completed or failed. Rollback does not occur immediately after the task fails. |
Both the task within a stage, and the stage | If a task fails, the task rollback runs. If the task is in a group of parallel tasks, the task rollback runs after all the parallel tasks have completed or failed. After the task rollback completes or fails to complete, the stage rollback runs. |
Consider a pipeline that has:
- A production stage with rollback.
- A group of parallel tasks, each task with its own rollback.
The task named UPD Deploy US has the rollback pipeline RB_Deploy_US. If UPD Deploy US fails, the rollback follows the flow defined in the RB_Deploy_US pipeline.
If UPD Deploy US fails, the RB_Deploy_US pipeline runs after UPD Deploy UK and UPD Deploy AU have also completed or failed. Rollback does not occur immediately after UPD Deploy US fails. And because the production stage also has rollback, after the RB_Deploy_US pipeline runs, the stage rollback pipeline runs.