Is there any way to stop AWS from starting CodePipeline automatically if I deploy it via CloudFormation?

Viewed 1343

If you create a CodePipeline via CloudFormation. It starts it automatically, that can be a problem because the pipeline can rewrite the same stack...

Is there any way to disable this behaviour?

Thanks.

4 Answers

Sadly, there seem to be no way of this this. Docs clearly states that a newly created pipeline immediately starts running:

Now that you've created your pipeline, you can view it in the console. The pipeline starts to run after you create it.

The initial run will always happen. Subsequent runs depend on your source action. For example, if you use CodeCommit as your source, you can disable CloudWatch Event that triggers the pipeline.

Thus if you want to use CodePipeline in your project, you have to design it so that it does not causes any issues due to immediate start.

Had same issue, I don't want a pipeline launch on pipeline creation (which is the default beahviour).

Best solution I fount is :

  1. Create an EventBridge rule which catch the pipelineExecution on pipeline creation
  2. Stop the pipeline execution from the lambda triggered

Rule looks like this :

{
  "source": ["aws.codepipeline"],
  "detail-type": ["CodePipeline Pipeline Execution State Change"],
  "detail": {
    "state": ["STARTED"],
    "execution-trigger": {
      "trigger-type": ["CreatePipeline"]
    }
  }
}

It works fine

Further to Marcin's comment, it would seem there are 2 approaches you can take which would limit the run of the pipeline.

  1. Create a disabled StageTransition or Manual Approval stage directly after the Source stage. This would prevent the pipeline executing any other action aside from getting the source which would have no impact or capability to re-write anything.

  2. Alternatively if your source stage is from a repository, you can opt to handle the pipeline triggers yourself by disabling the PollForSourceChanges parameter in your cloudformation template.

    Pipeline:
      Type: AWS::CodePipeline::Pipeline
      Properties:
        Name: *NAME*
        RoleArn: *IAMROLE*
        Stages:
          - Name: Source
            Actions:
              - Name: CodeCommitSourceAction
                RunOrder: 1
                ActionTypeId:
                  Category: Source
                  Provider: CodeCommit
                  Owner: AWS
                  Version: '1'
                OutputArtifacts:
                  - Name: Source
                Configuration:
                  RepositoryName: *REPOSITORYNAME*
                  BranchName: *BRANCH*
                  PollForSourceChanges: "false" #prevents codepipeline polling repository for  changes.
    

So the correct answer is...

  1. Commit your code before you deploy for the first time
  2. Deploy only the pipeline
  3. Let Code Pipeline do its thing

99% of cases it will finish sooner than your machine.

Related