Skip to content

Git tag rollback strategy code pipeline

1

Hi AWS people. I'm trying to run Code Pipeline based on Git tag. I know Code Pipeline does not support Git TAG strategy. Therefore, I designated the source as Amazon S3, not CodeCommit. S3 has my source compression file, so I can build it and deploy it.

But I have a problem. If I commit, I want to go back to commit ID. Even when I do this I always have to save my source on Amazon S3 and run code pipeline again. This will take a long time to build-deploy. I just want to go back to the built artifact. What should I do?

Here's what I think. Tag built artifacts stored on Amazon S3. And it's a way to specify the commit ID I want to return to the shell script.

Help me. Please make Code Pipeline support tag strategy.

1 Answer
0

There are now two different CodePipeline operations for these two requirements:

  1. Redeploy a previously built artifact without rebuilding it: roll back the Deploy stage to a previously successful pipeline execution.
  2. Build an arbitrary Git commit or a newly created Git tag: start a normal execution with a source revision override.

For the first requirement, CodePipeline stage rollback is the direct solution. When you roll back the Deploy stage, CodePipeline creates a new rollback execution and uses the variables and artifacts from the target execution. The Source and Build stages are not rerun, so this redeploys the artifact that was already produced by that earlier successful execution.

In the console, open the pipeline, choose Start rollback on the Deploy stage, and select the successful execution that contains the artifact you want. The CLI equivalent is:

aws codepipeline list-pipeline-executions   --pipeline-name MyPipeline   --filter succeededInStage={stageName=Deploy}

aws codepipeline rollback-stage   --pipeline-name MyPipeline   --stage-name Deploy   --target-pipeline-execution-id <successful-execution-id>

Use the name of the stage containing the CodeDeploy action. Do not roll back the Build stage if the goal is to avoid rebuilding.

Important rollback limits are:

  • A Source stage cannot be rolled back.
  • The target must have succeeded in that stage.
  • The target execution must belong to the current pipeline structure version.
  • A rollback execution cannot itself be used as the next rollback target.
  • The stage must not already be running.

You can also configure an OnFailure stage condition with a ROLLBACK result for automatic deployment rollback. Remember that stage rollback reuses CodePipeline variables and artifacts; it does not automatically reverse database migrations or other external side effects performed by deployment scripts.

For the second requirement, an S3 source archive is no longer required merely to choose a CodeCommit commit. CodePipeline supports COMMIT_ID source revision overrides. A tag-created CodeCommit EventBridge event contains detail.commitId; an input transformer can pass that value as the source action's sourceRevisions[].revisionValue. Alternatively, start it manually:

aws codepipeline start-pipeline-execution   --name MyPipeline   --source-revisions     actionName=Source,revisionType=COMMIT_ID,revisionValue=<commit-id>

That starts a normal Source/Build/Deploy execution for the selected commit. It is useful for a new tag, but it is not the no-rebuild rollback path. Use Deploy-stage rollback when the desired artifact already exists in a successful pipeline execution.

Official references:

answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.