Retry a failed action in a stage - AWS CodePipeline

Retry a failed action in a stage

You can retry a stage that has failed without having to run a pipeline again from the beginning. You do this by either retrying the failed actions in a stage or by retrying all actions in the stage starting from the first action in the stage. When you retry the failed actions in a stage, all actions that are still in progress continue working, and failed actions are triggered again. When you retry a failed stage from the first action in the stage, the stage cannot have any actions in progress. Before a stage can be retried, it must either have all actions failed or some actions failed and some succeeded.

Important

Retrying a failed stage retries all actions in the stage from the first action in the stage, and retrying failed actions retries all failed actions in the stage. This overrides output artifacts of previously successful actions in the same execution.

Although artifacts may be overriden, the execution history of previously successful actions is still retained.

If you are using the console to view a pipeline, either a Retry stage button or a Retry failed actions button appears on the stage that can be retried.

If you are using the AWS CLI, you can use the get-pipeline-state command to determine whether any actions have failed.

Note

In the following cases, you might not be able to retry a stage:

  • All actions in the stage succeeded, and so the stage is not in a failed status.

  • The overall pipeline structure changed after the stage failed.

  • Another retry attempt in the stage is already in progress.

Retry failed actions (console)

To retry a failed stage or failed actions in a stage - console
  1. Sign in to the AWS Management Console and open the CodePipeline console at http://console.aws.amazon.com/codesuite/codepipeline/home.

    The names of all pipelines associated with your AWS account are displayed.

  2. In Name, choose the name of the pipeline.

  3. Locate the stage with the failed action, and then choose one of the following:

    • To retry all actions in the stage, choose Retry stage.

    • To retry only failed actions in the stage, choose Retry failed actions.

    
                An example pipeline with a CodeCommit source stage and a failed CodeDeploy deploy
                    stage

    If all retried actions in the stage are completed successfully, the pipeline continues to run.

Retry failed actions (CLI)

To retry a failed stage or failed actions in a stage - CLI

To use the AWS CLI to retry all actions or all failed actions, you run the retry-stage-execution command with the following parameters:

--pipeline-name <value> --stage-name <value> --pipeline-execution-id <value> --retry-mode ALL_ACTIONS/FAILED_ACTIONS
Note

The values you can use for retry-mode are FAILED_ACTIONS and ALL_ACTIONS.

  1. At a terminal (Linux, macOS, or Unix) or command prompt (Windows), run the retry-stage-execution command, as shown in the following example for a pipeline named MyPipeline.

    aws codepipeline retry-stage-execution --pipeline-name MyPipeline --stage-name Deploy --pipeline-execution-id b59babff-5f34-EXAMPLE --retry-mode FAILED_ACTIONS

    The output returns the execution ID:

    { "pipelineExecutionId": "b59babff-5f34-EXAMPLE" }
  2. You can also run the command with a JSON input file. You first create a JSON file that identifies the pipeline, the stage that contains the failed actions, and the latest pipeline execution in that stage. You then run the retry-stage-execution command with the --cli-input-json parameter. To retrieve the details you need for the JSON file, it's easiest to use the get-pipeline-state command.

    1. At a terminal (Linux, macOS, or Unix) or command prompt (Windows), run the get-pipeline-state command on a pipeline. For example, for a pipeline named MyFirstPipeline, you would type something similar to the following:

      aws codepipeline get-pipeline-state --name MyFirstPipeline

      The response to the command includes pipeline state information for each stage. In the following example, the response indicates that one or more actions failed in the Staging stage:

      { "updated": 1427245911.525, "created": 1427245911.525, "pipelineVersion": 1, "pipelineName": "MyFirstPipeline", "stageStates": [ { "actionStates": [...], "stageName": "Source", "latestExecution": { "pipelineExecutionId": "9811f7cb-7cf7-SUCCESS", "status": "Succeeded" } }, { "actionStates": [...], "stageName": "Staging", "latestExecution": { "pipelineExecutionId": "3137f7cb-7cf7-EXAMPLE", "status": "Failed" } } ] }
    2. In a plain-text editor, create a file where you will record the following, in JSON format:

      • The name of the pipeline that contains the failed actions

      • The name of the stage that contains the failed actions

      • The ID of the latest pipeline execution in the stage

      • The retry mode.

      For the preceding MyFirstPipeline example, your file would look something like this:

      { "pipelineName": "MyFirstPipeline", "stageName": "Staging", "pipelineExecutionId": "3137f7cb-7cf7-EXAMPLE", "retryMode": "FAILED_ACTIONS" }
    3. Save the file with a name like retry-failed-actions.json.

    4. Call the file you created when you run the retry-stage-execution command. For example:

      Important

      Be sure to include file:// before the file name. It is required in this command.

      aws codepipeline retry-stage-execution --cli-input-json file://retry-failed-actions.json
    5. To view the results of the retry attempt, either open the CodePipeline console and choose the pipeline that contains the actions that failed, or use the get-pipeline-state command again. For more information, see View pipelines and details in CodePipeline.