Edit a pipeline in CodePipeline - AWS CodePipeline

Edit a pipeline in CodePipeline

A pipeline describes the release process that you want AWS CodePipeline to follow, including stages and actions that must be completed. You can edit a pipeline to add or remove these elements. However, when you edit a pipeline, values such as the pipeline name or pipeline metadata cannot be changed.

You can edit your pipeline type, variables, and triggers using the pipeline edit page. You can also add or change stages and actions in your pipeline.

Unlike creating a pipeline, editing a pipeline does not rerun the most recent revision through the pipeline. If you want to run the most recent revision through a pipeline you've just edited, you must manually rerun it. Otherwise, the edited pipeline runs the next time you make a change to a source location configured in the source stage. For information, see Start a pipeline manually.

You can add actions to your pipeline that are in an AWS Region different from your pipeline. When an AWS service is the provider for an action, and this action type/provider type are in a different AWS Region from your pipeline, this is a cross-Region action. For more information about cross-Region actions, see Add a cross-Region action in CodePipeline.

CodePipeline uses change detection methods to start your pipeline when a source code change is pushed. These detection methods are based on source type:

  • CodePipeline uses Amazon CloudWatch Events to detect changes in your CodeCommit source repository or your Amazon S3 source bucket.

Note

Change detection resources are created automatically when you use the console. When you use the console to create or edit a pipeline, the additional resources are created for you. If you use the AWS CLI to create the pipeline, you must create the additional resources yourself. For more information about creating or updating a CodeCommit pipeline, see Create an EventBridge rule for a CodeCommit source (CLI). For more information about using the CLI to create or update an Amazon S3 pipeline, see Create an EventBridge rule for an Amazon S3 source (CLI).

Edit a pipeline (console)

You can use the CodePipeline console to add, edit, or remove stages in a pipeline and to add, edit, or remove actions in a stage.

When you update a pipeline, CodePipeline gracefully completes all the running actions and then fails the stages and pipeline executions where the running actions were completed. When a pipeline is updated, you will need to re-run your pipeline. For more information on running a pipeline, see Start a pipeline manually.

To edit a pipeline
  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 you want to edit. This opens a detailed view of the pipeline, including the state of each of the actions in each stage of the pipeline.

  3. On the pipeline details page, choose Edit.

  4. To edit the pipeline type, choose Edit on the Edit: Pipeline properties card. Choose one of the following options, and then choose Done.

    • V1 type pipelines have a JSON structure that contains standard pipeline, stage, and action-level parameters.

    • V2 type pipelines have the same structure as a V1 type, along with additional parameter support, such as triggers and pipeline-level variables.

    Pipeline types differ in characteristics and price. For more information, see Pipeline types.

  5. To edit the pipeline variables, choose Edit variables on the Edit: Variables card. Add or change variables for the pipeline level, and then choose Done.

    For more information about variables at the pipeline level, see Variables reference. For a tutorial with a pipeline-level variable that is passed at the time of the pipeline execution, see Tutorial: Use pipeline-level variables.

    Note

    While it is optional to add variables at the pipeline level, for a pipeline specified with variables at the pipeline level where no values are provided, the pipeline execution will fail.

  6. To edit the pipeline triggers, choose Edit triggers on the Edit: Triggers card. Add or change triggers, and then choose Done.

    For more information about adding triggers, see the steps for creating a connection to Bitbucket Cloud, GitHub (Version 2), GitHub Enterprise Server, GitLab.com, or GitLab self-managed, such as GitHub connections.

  7. To edit stages and actions on the Edit page, do one of the following:

    • To edit a stage, choose Edit stage. You can add actions in serial and parallel with existing actions:

      You can also edit actions in this view by choosing the edit icon for those actions. To delete an action, choose the delete icon on that action.

    • To edit an action, choose the edit icon for that action, and then on Edit action, change the values. Items marked with an asterisk (*) are required.

      • For a CodeCommit repository name and branch, a message appears showing the Amazon CloudWatch Events rule to be created for this pipeline. If you remove the CodeCommit source, a message appears showing the Amazon CloudWatch Events rule to be deleted.

      • For an Amazon S3 source bucket, a message appears showing the Amazon CloudWatch Events rule and AWS CloudTrail trail to be created for this pipeline. If you remove the Amazon S3 source, a message appears showing the Amazon CloudWatch Events rule and AWS CloudTrail trail to be deleted. If the AWS CloudTrail trail is in use by other pipelines, the trail is not removed and the data event is deleted.

    • To add a stage, choose + Add stage at the point in the pipeline where you want to add a stage. Provide a name for the stage, and then add at least one action to it. Items marked with an asterisk (*) are required.

    • To delete a stage, choose the delete icon on that stage. The stage and all of its actions are deleted.

    • To configure a stage to roll back automatically on failure, choose Edit stage, and then choose the checkbox Configure automatic rollback on stage failure.

    For example, if you wanted to add a serial action to a stage in a pipeline:

    1. In the stage where you want to add your action, choose Edit stage, and then choose + Add action group.

    2. In Edit action, in Action name, enter the name of your action. The Action provider list displays provider options by category. Look for the category (for example, Deploy). Under the category, choose the provider (for example, AWS CodeDeploy). In Region, choose the AWS Region where the resource is created or where you plan to create it. The Region field designates where the AWS resources are created for this action type and provider type. This field only displays for actions where the action provider is an AWS service. The Region field defaults to the same AWS Region as your pipeline.

      For examples of adding action providers and using the default fields for each provider, see Create a custom pipeline (console).

      To add CodeBuild as a build action or test action to a stage, see Use CodePipeline with CodeBuild to Test Code and Run Builds in the CodeBuild User Guide.

      Note

      Some action providers, such as GitHub, require you to connect to the provider's website before you can complete the configuration of the action. When you connect to a provider's website, make sure you use the credentials for that website. Do not use your AWS credentials.

    3. When you have finished configuring your action, choose Save.

    Note

    You cannot rename a stage in the console view. You can add a stage with the name you want to change, and then delete the old one. Make sure you have added all the actions you want in that stage before you delete the old one.

  8. When you have finished editing your pipeline, choose Save to return to the summary page.

    Important

    After you save your changes, you cannot undo them. You must edit the pipeline again. If a revision is running through your pipeline when you save your changes, the run is not completed. If you want a specific commit or change to run through the edited pipeline, you must manually run it through the pipeline. Otherwise, the next commit or change runs automatically through the pipeline.

  9. To test your action, choose Release change to process that commit through the pipeline and commit a change to the source specified in the source stage of the pipeline. Or follow the steps in Start a pipeline manually to use the AWS CLI to manually release a change.

Edit a pipeline (AWS CLI)

You can use the update-pipeline command to edit a pipeline.

When you update a pipeline, CodePipeline gracefully completes all the running actions and then fails the stages and pipeline executions where the running actions were completed. When a pipeline is updated, you will need to re-run your pipeline. For more information on running a pipeline, see Start a pipeline manually.

Important

Although you can use the AWS CLI to edit pipelines that include partner actions, you must not manually edit the JSON of a partner action. If you do so, the partner action fails after you update the pipeline.

To edit a pipeline
  1. Open a terminal session (Linux, macOS, or Unix) or command prompt (Windows) and run the get-pipeline command to copy the pipeline structure into a JSON file. For example, for a pipeline named MyFirstPipeline, enter the following command:

    aws codepipeline get-pipeline --name MyFirstPipeline >pipeline.json

    This command returns nothing, but the file you created should appear in the directory where you ran the command.

  2. Open the JSON file in any plain-text editor and modify the structure of the file to reflect the changes you want to make to the pipeline. For example, you can add or remove stages, or add another action to an existing stage.

    The following example shows how you would add another deployment stage in the pipeline.json file. This stage runs after the first deployment stage named Staging.

    Note

    This is just a portion of the file, not the entire structure. For more information, see CodePipeline pipeline structure reference.

    , { "name": "Staging", "actions": [ { "inputArtifacts": [ { "name": "MyApp" } ], "name": "Deploy-CodeDeploy-Application", "actionTypeId": { "category": "Deploy", "owner": "AWS", "version": "1", "provider": "CodeDeploy" }, "outputArtifacts": [], "configuration": { "ApplicationName": "CodePipelineDemoApplication", "DeploymentGroupName": "CodePipelineDemoFleet" }, "runOrder": 1 } ] }, { "name": "Production", "actions": [ { "inputArtifacts": [ { "name": "MyApp" } ], "name": "Deploy-Second-Deployment", "actionTypeId": { "category": "Deploy", "owner": "AWS", "version": "1", "provider": "CodeDeploy" }, "outputArtifacts": [], "configuration": { "ApplicationName": "CodePipelineDemoApplication", "DeploymentGroupName": "CodePipelineProductionFleet" }, "runOrder": 1 } ] } ] }

    For information about using the CLI to add an approval action to a pipeline, see Add a manual approval action to a pipeline in CodePipeline .

    Make sure the PollForSourceChanges parameter in your JSON file is set as follows:

    "PollForSourceChanges": "false",

    CodePipeline uses Amazon CloudWatch Events to detect changes in your CodeCommit source repository and branch or your Amazon S3 source bucket. The next step includes instructions for creating these resources manually. Setting the flag to false disables periodic checks, which are not required when you use the recommended change detection methods.

  3. To add a build, test, or deploy action in a Region different from your pipeline, you must add the following to your pipeline structure. For detailed instructions, see Add a cross-Region action in CodePipeline.

    • Add the Region parameter to your action's pipeline structure.

    • Use the artifactStores parameter to specify an artifact bucket for each Region where you have an action.

  4. If you are working with the pipeline structure retrieved using the get-pipeline command, you must modify the structure in the JSON file. You must remove the metadata lines from the file so the update-pipeline command can use it. Remove the section from the pipeline structure in the JSON file (the "metadata": { } lines and the "created", "pipelineARN", and "updated" fields).

    For example, remove the following lines from the structure:

    "metadata": { "pipelineArn": "arn:aws:codepipeline:region:account-ID:pipeline-name", "created": "date", "updated": "date" }

    Save the file.

  5. If you use the CLI to edit a pipeline, you must manually manage the recommended change detection resources for your pipeline:

  6. To apply your changes, run the update-pipeline command, specifying the pipeline JSON file:

    Important

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

    aws codepipeline update-pipeline --cli-input-json file://pipeline.json

    This command returns the entire structure of the edited pipeline.

    Note

    The update-pipeline command stops the pipeline. If a revision is being run through the pipeline when you run the update-pipeline command, that run is stopped. You must start the pipeline manually to run that revision through the updated pipeline.

  7. Open the CodePipeline console and choose the pipeline you just edited.

    The pipeline shows your changes. The next time you make a change to the source location, the pipeline runs that revision through the revised structure of the pipeline.

  8. To manually run the last revision through the revised structure of the pipeline, run the start-pipeline-execution command. For more information, see Start a pipeline manually.

For more information about the structure of a pipeline and expected values, see CodePipeline pipeline structure reference and AWS CodePipeline API Reference.