aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

CodePipeline add multiple source CodeCommit on the same stage

Open cesarpball opened this issue 6 years ago • 6 comments

The Question

I want to add multiple source stages from CodeCommit to trigger the same pipeline depending on the branch (master,dev,qa)

       source_output = codepipeline.Artifact()
       master_action = codepipeline_actions.CodeCommitSourceAction(
           action_name="Codemaster",
           repository=repo,
           output=source_output,
           branch="master"
       )
       devaction = codepipeline_actions.CodeCommitSourceAction(
           action_name="Codedev",
           repository=repo,
           output=source_output,
           branch="dev"
       )
       qaaction = codepipeline_actions.CodeCommitSourceAction(
           action_name="Codeqa",
           repository=repo,
           output=source_output,
           branch="qa"
       )
       pipeline.add_stage(
           stage_name="SourceCode",
           actions=[master_action,devaction,qaaction]
       )

Then I get the issue:

jsii.errors.JavaScriptError: 
  Error: There is already a Construct with name 'dockerpipeline2F0CA39F7EventRule' in Repository [docker-repo]
      at Node.addChild (/private/var/folders/1b/0_087b815pq9q3gd01q32s845c1810/T/jsii-kernel-gXpn5y/node_modules/constructs/lib/construct.js:414:19)

I can add multiple actions in the CodeBuild part, but I am getting an error here. I can add manually trough the AWS console and it's fine.

Environment

  • CDK CLI Version: 1.36.1 (build 4df7dac
  • Module Version:
  • OS: OSX Mojave
  • Language: Python

cesarpball avatar May 05 '20 15:05 cesarpball

Hey @cesarpball ,

you're right, this is a bug in the CodeCommitSourceAction.

To unblock yourself while I fix this, you can disable CloudWatch Events (which are the root cause of this issue) in all Actions observing that repository beyond the first:

       master_action = codepipeline_actions.CodeCommitSourceAction(
           # same as yours...
       )
       devaction = codepipeline_actions.CodeCommitSourceAction(
           # as above...
           trigger=codepipeline_actions.CodeCommitTrigger.POLL,
       )
       qaaction = codepipeline_actions.CodeCommitSourceAction(
           # as above...
           trigger=codepipeline_actions.CodeCommitTrigger.POLL,
       )

Thanks, Adam

skinny85 avatar May 06 '20 23:05 skinny85

I'm also getting this issue, but not with Cloudwatch. It informs I cannot have a single output with a build step. I have an array of services in a typescript loop; is there a workaround? Thanks

ZakHargz avatar Sep 26 '20 17:09 ZakHargz

Hello @ZakHargz ,

It informs I cannot have a single output with a build step

Can you show the relevant code fragment, and the exact error CDK returns?

Thanks, Adam

skinny85 avatar Sep 28 '20 14:09 skinny85

I'm also experiencing the same issue, however the issue is observed in TypeScript and not Python.

Below is the Python snippet which is synthesized without any issues:

        main_action = codepipeline_actions.CodeCommitSourceAction(
            action_name = 'CodeCommit',
            repository = repoMain,
            output = main_output,
            branch = 'main',
            trigger = codepipeline_actions.CodeCommitTrigger.EVENTS
        )

        dev_action = codepipeline_actions.CodeCommitSourceAction(
            action_name = 'CodeCommitDev',
            repository = repoDev,
            output = dev_output,
            branch = 'main',
            trigger = codepipeline_actions.CodeCommitTrigger.EVENTS
        )

        pipeline.add_stage(
            stage_name = 'Source',
            actions = [main_action, dev_action]
        )

Below is the TypeScript snippet which experiences the following issue:

Error: There is already a Construct with name 'PipelineStackCICDPipelineA3579475-main-EventRule' in Repository [MyDenoRepo]

    const main_action = new codepipeline_actions.CodeCommitSourceAction({
      actionName: 'CodeCommit',
      repository: repoMain,
      output: main_output,
      branch: 'main',
      trigger: codepipeline_actions.CodeCommitTrigger.EVENTS
    })

    const dev_action = new codepipeline_actions.CodeCommitSourceAction({
      actionName: 'CodeCommitDev',
      repository: repoDev,
      output: dev_output,
      branch: 'main',
      trigger: codepipeline_actions.CodeCommitTrigger.EVENTS
    })

    pipeline.addStage({
      stageName: 'Source',
      actions: [main_action, dev_action] 
    })

While employing POLL is effective in TypeScript, I'd prefer to utilize EVENTS. Can you kindly advice whether the PR that fixed the problem in Python has also been applied to TypeScript, or is it a future development?

sirmattx avatar Oct 23 '23 09:10 sirmattx

@sirmattx yes, it should have fixed it for both (the Python code is generated from the TypeScript code).

Can you check what version of the CDK libraries you are using in your TypeScript program?

skinny85 avatar Oct 24 '23 06:10 skinny85

I just updated my CDK version from v2.87.0 to v2.102.0 and I do see the issue is not there anymore, thanks @skinny85

sirmattx avatar Oct 24 '23 08:10 sirmattx