You configure rollback as a pipeline with tasks that return your deployment to a previous stable state following a failure in a deployment pipeline. To roll back if a failure occurs, you attach the rollback pipeline to tasks or stages.

Depending upon your role, your reasons for rollback might vary.

  • As a release engineer, I want Code Stream to verify success during a release so that I can know whether to continue with the release or roll back. Possible failures include task failure, a rejection in UserOps, exceeding the metrics threshold.
  • As an environment owner, I want to redeploy a previous release so that I can quickly get an environment back to a known-good state.
  • As an environment owner, I want to support roll back of a Blue-Green deployment so that I can minimize downtime from failed releases.

When you use a smart pipeline template to create a CD pipeline with the rollback option clicked, rollback is automatically added to tasks in the pipeline. In this use case, you will use the smart pipeline template to define rollback for an application deployment to a Kubernetes cluster using the rolling upgrade deployment model. The smart pipeline template creates a deployment pipeline and one or more rollback pipelines.

  • In the deployment pipeline, rollback is required if Update Deployment or Verify Deployment tasks fail.
  • In the rollback pipeline, deployment is updated with an old image.

You can also manually create a rollback pipeline using a blank template. Before creating a rollback pipeline, you will want to plan your rollback flow. For more background information about rollback, see Planning for rollback in Code Stream.

Prerequisites

  • Verify that you are a member of a project in Code Stream. If you are not, ask a Code Stream administrator to add you as a member of a project. See How do I add a project in Code Stream.
  • Set up the Kubernetes clusters where your pipeline will deploy your application. Set up one development cluster and one production cluster.
  • Verify that you have a Docker registry setup.
  • Identify a project that will group all your work, including your pipeline, endpoints, and dashboards.
  • Familiarize yourself with the CD smart template as described in the CD portion of Planning a CICD native build in Code Stream before using the smart pipeline template, for example:
    • Create the Kubernetes development and production endpoints that deploy your application image to the Kubernetes clusters.
    • Prepare the Kubernetes YAML file that creates the Namespace, Service, and Deployment. If you need to download an image from a privately-owned repository, the YAML file must include a section with the Docker config Secret.

Procedure

  1. Click Pipelines > New Pipeline > Smart Template > Continuous Delivery.
  2. Enter the information in the smart pipeline template.
    1. Select a project.
    2. Enter a pipeline name such as RollingUpgrade-Example.
    3. Select the environments for your application. To add rollback to your deployment, you must select Prod.
    4. Click Select, choose a Kubernetes YAML file, and click Process.
      The smart pipeline template displays the available services and deployment environments.
    5. Select the service that the pipeline will use for the deployment.
    6. Select the cluster endpoints for the Dev environment and the Prod environment.
    7. For the Image source, select Pipeline runtime input.
    8. For the Deployment model, select Rolling Upgrade.
    9. Click Rollback.
    10. Provide the Health check URL.
    When you create a rollback pipeline, you enter the details, select a service, deployment, and deployment model, and mark the Rollback check box.
  3. To create the pipeline named RollbackUpgrade-Example, click Create.

    The pipeline named RollbackUpgrade-Example appears, and the rollback icon appears on tasks that can roll back in the Development stage and the Production stage.

    On a rollback pipeline, the rollback icon appears on tasks where the pipeline can rollback.

  4. Close the pipeline.

    On the Pipelines page, the pipeline that you created appears, and a new pipeline for each stage in your pipeline appears.

    • RollingUpgrade-Example. Code Stream deactivates the pipeline that you created by default, which ensures that you review it before you run it.
    • RollingUpgrade-Example_Dev_Rollback. Failure of tasks in the development stage, such as Create service, Create secret, Create deployment, and Verify deployment invoke this rollback development pipeline. To ensure the rollback of development tasks, Code Stream activates the rollback development pipeline by default.
    • RollingUpgrade-Example_Prod_Rollback. Failure of tasks in the production stage, such as Deploy phase 1, Verify phase 1, Deploy Rollout phase, Finish Rollout phase, and Verify rollout phase invoke this rollback production pipeline. To ensure the rollback of production tasks, Code Stream activates the rollback production pipeline by default.
    Code Stream creates rollback pipelines for the stages, and activates them.
  5. Enable and run the pipeline you created.
    When you start the run, Code Stream prompts you for input parameters. You provide the image and tag for the endpoint in the Docker repository that you are using.
  6. On the Executions page, select Actions > View Execution and watch the pipeline execution.

    The pipeline starts RUNNING and moves through the Development stage tasks. If the pipeline fails to run a task during the Development stage, the pipeline named RollingUpgrade-Example_Dev_Rollback triggers and rolls back the deployment, and the pipeline status changes to ROLLING_BACK.

    The rollback pipeline rolls back the deployment and returns the pipeline to the previous stable state.

    After rollback, the Executions page lists two RollingUpgrade-Example pipeline executions.

    • The pipeline you created rolled back and displays ROLLBACK_COMPLETED.
    • The rollback development pipeline that triggered and performed the rollback displays COMPLETED.

    The rollback results appear on the Executions tab, and the comments display the trigger point of the rollback.

Results

Congratulations! You successfully defined a pipeline with rollback and watched Code Stream roll back the pipeline at the point of failure.