Start Building for Free
CircleCI.comAcademyBlogCommunitySupport

Set up rollbacks in CircleCI

1 month ago2 min read
Cloud
On This Page

Rollbacks allow you to quickly revert your application to a previous stable version when issues are detected in production. This guide covers how to configure your CircleCI pipeline to support manual rollback capabilities.

Prerequisites

Set up rollbacks

1. Manually configure deploy markers

If not already set up, you must configure deploy markers in your CircleCI workflows. Deploy markers track when deployments occur and are essential for rollback functionality. Follow the Configure Deploy Markers guide to set this up. Autodetected deploy markers are not supported for use with rollbacks.

The rest of this guide covers how to set up rollbacks using a custom rollback pipeline. At this point, after deploy markers are configured, you can use the Rollback by workflow rerun method.

2. Navigate to project overview

  1. In the CircleCI dashboard, navigate to Organization Home from the sidebar.

  2. Select the Overview link for your project.

You will see a red Rollback button with a dropdown option on the project overview page.

Rollback button on project overview page
Figure 1. Rollback options on project overview page

2. Start the rollback setup

  1. Select the Rollback dropdown.

  2. Select Set up custom rollback pipeline from the dropdown menu. This launches the rollback setup wizard.

The setup wizard guides you through configuring your custom rollback pipeline.

Set up a rollback pipeline

3. Configure the rollback pipeline

  1. From the "What repo are you deploying?" dropdown, select the repository you want to create rollbacks for.

  2. Select Create pipeline definition to proceed.

CircleCI creates a pipeline definition called rollback-pipeline and use the selected repository to store your rollback configuration.

4. Review the generated configuration

After creating the pipeline definition, the modal will display a pre-generated configuration file for performing rollbacks.

  1. Review the generated YAML configuration template to ensure you understand the rollback pipeline.

  2. Select Commit Config to create this rollback configuration template in your repository. The configuration will be committed to a new branch called rollback-pipeline-setup in your selected repository.

This config is a template rollback pipeline that includes the following:

  • Parameters section: Placeholder parameters that you can customize for your specific deployment needs

  • Jobs section: A basic rollback job structure with common rollback configuration setups included (but commented out)

After committing, you can modify the configuration according to your needs by setting your own parameters and rollback logic. You can uncomment the included common rollback setups or write your own custom rollback implementation.

5. Create pull request

After committing the configuration template, the final step is to create a pull request:

  1. Select Create PR to generate a pull request with your rollback configuration.

    Create PR for rollback pipeline
  2. Navigate to the pull request in your repository and modify the rollback configuration according to your specific deployment needs.

  3. Once you have customized the configuration, merge the pull request to complete the rollback setup.

Configuration tips

When customizing your rollback configuration, you can use the following pipeline values to access rollback values:

  • pipeline.deploy.component_name

  • pipeline.deploy.environment_name

  • pipeline.deploy.target_version

  • pipeline.deploy.current_version

  • pipeline.deploy.namespace

Deploy markers for rollbacks

You can use deploy markers with the --rollback flag to indicate rollback deployment:

circleci run release plan \
          --environment-name=${ENVIRONMENT_NAME} \
          --namespace=${NAMESPACE} \
          --component-name=${COMPONENT_NAME} \
          --target-version=${TARGET_VERSION} \
          --rollback

You can also update the status of the rollback deployment as mentioned in the Configure Deploy Markers guide to reflect the state of the rollback accurately in the CircleCI UI.

6. Access rollback functionality

Once the pull request is merged, the rollback setup is complete. You can now use the rollback functionality in the CircleCI UI. For a full guide, see the Rollback a project using the rollback pipeline guide.


Suggest an edit to this page

Make a contribution
Learn how to contribute