How can I fix AWS CodePipeline when it runs twice?

Last updated: 2020-02-13

My AWS CodePipeline runs twice. How can I resolve this issue?

Short Description

First, read the Understand the default behavior of the PollForSourceChanges parameter section.

Then, based on your scenario, complete the steps in one of the following sections:

  • If you created your pipeline with AWS CloudFormation, complete the steps in the Update your AWS CloudFormation template section.
  • If you created your pipeline with the AWS Command Line Interface (AWS CLI), complete the steps in the Update your pipeline with a JSON file section.
  • If you created your pipeline with the AWS SDK, complete the steps in the Update your pipeline based on the configuration syntax of your language section.

If your pipeline still runs twice after completing the steps in the preceding sections, then complete the steps in the Check your Amazon CloudWatch Events rules section.

Important: Update your pipeline using the same method that you created it with. Avoid making out-of-band changes to your pipeline, and be sure to complete the steps in the section that applies to your scenario only. For example, if you created your pipeline with AWS CloudFormation, then strictly follow the Update your AWS CloudFormation template section only.

Resolution

Understand the default behavior of the PollForSourceChanges parameter

Consider the following:

  • The default behavior of the PollForSourceChanges parameter is determined by the method used to create the pipeline.
  • In many cases, the value of PollForSourceChanges is set to true by default and must be disabled.
    If you create your pipeline with the CodePipeline console, then the source detection method is automatically set to Amazon CloudWatch Events (the recommended way of detecting change in your source).
  • If you create your pipeline with AWS CloudFormation, the AWS CLI, or the AWS SDK and don't specify the change detection method, then PollForSourceChanges is set to true by default (depending on the creation method).
  • If you create your pipeline using a method other than the CodePipeline console and then update your pipeline out-of-band without using the console, then CodePipeline automatically creates an extra CloudWatch Events rule.
  • If you create a CloudWatch Events rule in your AWS CloudFormation template or create a webhook for your GitHub repository and don't set the PollForSourceChanges parameter, then you end up with two ways to detect changes in the source. This makes your pipeline run twice.

Update your AWS CloudFormation template

In your AWS CloudFormation template or pipeline configuration file, set the PollForSourceChanges parameter to false.

Note: The PollForSourceChanges parameter is set to true by default.

For more information, see Create a Webhook for a GitHub Source (AWS CloudFormation Template).

Update your pipeline with a JSON file

1.    Copy your pipeline structure to a JSON file:

$ aws codepipeline get-pipeline --name NAME_OF_YOUR_PIPELINE  > pipeline.json

2.    Open the pipeline.json file in a text editor, and then add the PollForSourceChanges parameter to the configuration section. Set the parameter to false.

Note: For more information, see Edit a Pipeline (AWS CLI).

3.    Save the pipeline.json file, and then run the following command to apply the changes to the file:

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

For an example, see Create a Webhook for a GitHub Source.

Update your pipeline based on the configuration syntax of your language

For instructions on updating your pipeline, see the SDK documentation for your language.

For example, if you deployed your pipeline with Python, you can set PollForSourceChanges to false in the configuration section of your pipeline.

Check your Amazon CloudWatch Events rules

Check if there are any CloudWatch Events rules that have the same target as your pipeline, and then delete or disable any duplicate rules.


Did this article help you?

Anything we could improve?


Need more help?