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

5

5

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.

Baste answered 23/6, 2020 at 17:45 Comment(0)
T
4

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

Trimer answered 16/12, 2021 at 16:27 Comment(0)
C
1

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.

Chiquita answered 24/6, 2020 at 0:54 Comment(4)
"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." Any idea how?Baste
@artit91 Unfortunately, from your very short description of the issue, its difficult to say anything. You would have to write new question with all relevant details, such as what is the architecture of your pipeline (e.g. what is the source stage), what is its outcome, what do you mean it can "rewrite the same stack"? Which stack?Chiquita
just build in a disabled stage transition after the initial source stage.Tiffie
@Tiffie Yes, you could do this using StageTransition but the first read of the source will still execute. Maybe you can add an answer. It seems as a good compromise?Chiquita
D
1

You can disable the Event rule from automatically starting your pipeline. Go to Amazon EventBridge -> Rules and disable the rule that notifies the CodePipeline.

enter image description here

Draftee answered 15/12, 2022 at 15:16 Comment(0)
T
0

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.
    
Tiffie answered 24/6, 2020 at 21:46 Comment(0)
A
0

I've just run into this myself and a search brought me here. In my case I'm using Terraform - same outcome.

The event bridge stuff looks too complicated for me and I don't want to try to create the pipeline first with manual run enabled, then update it again enabled.

So I started looking at what environment strings are available to the build that may help. https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html

I found this one CODEBUILD_BUILD_NUMBER

If CODEBUILD_BUILD_NUMBER is 1 then it's simply the first time this pipeline is running since it's been created. Just add a line that aborts the build if CODEBUILD_BUILD_NUMBER is 1.

- if [ $CODEBUILD_BUILD_NUMBER -eq 1 ]; then echo 'aborting first build' && exit 1; fi
Alix answered 2/2 at 1:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.