Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodePipeline add multiple source CodeCommit on the same stage #7802

Closed
cesarpball opened this issue May 5, 2020 · 6 comments · Fixed by #8018
Closed

CodePipeline add multiple source CodeCommit on the same stage #7802

cesarpball opened this issue May 5, 2020 · 6 comments · Fixed by #8018
Assignees
Labels
@aws-cdk/aws-codecommit Related to AWS CodeCommit @aws-cdk/aws-codepipeline Related to AWS CodePipeline bug This issue is a bug. in-progress This issue is being actively worked on. p1

Comments

@cesarpball
Copy link

cesarpball commented May 5, 2020

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 cesarpball added the needs-triage This issue or PR still needs to be triaged. label May 5, 2020
@SomayaB SomayaB added guidance Question that needs advice or information. @aws-cdk/aws-codepipeline Related to AWS CodePipeline @aws-cdk/aws-codecommit Related to AWS CodeCommit labels May 5, 2020
@skinny85
Copy link
Contributor

skinny85 commented May 6, 2020

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 skinny85 added bug This issue is a bug. p1 and removed guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels May 6, 2020
skinny85 added a commit to skinny85/aws-cdk that referenced this issue May 15, 2020
There are use-cases when you want to add the same CodeCommit
repository to a CodePipeline multiple times, with different branches.
This wouldn't work when using CloudWatch Events to trigger the pipeline,
as the ID of the generated Event only used the pipeline ID for uniqueness.
Change it to also use the branch name when generating the Event ID
(which cannot be empty, as it turns out, so validate that as well).

Fixes aws#7802
@SomayaB SomayaB added the in-progress This issue is being actively worked on. label May 15, 2020
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Jun 1, 2020
There are use-cases when you want to add the same CodeCommit
repository to a CodePipeline multiple times, with different branches.
This wouldn't work when using CloudWatch Events to trigger the pipeline,
as the ID of the generated Event only used the pipeline ID for uniqueness.
Change it to also use the branch name when generating the Event ID
(which cannot be empty, as it turns out, so validate that as well).

Fixes aws#7802
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Jun 2, 2020
There are use-cases when you want to add the same CodeCommit
repository to a CodePipeline multiple times, with different branches.
This wouldn't work when using CloudWatch Events to trigger the pipeline,
as the ID of the generated Event only used the pipeline ID for uniqueness.
Change it to also use the branch name when generating the Event ID
(which cannot be empty, as it turns out, so validate that as well).

Fixes aws#7802
@mergify mergify bot closed this as completed in #8018 Jun 2, 2020
mergify bot pushed a commit that referenced this issue Jun 2, 2020
…nts (#8018)

There are use-cases when you want to add the same CodeCommit
repository to a CodePipeline multiple times, with different branches.
This wouldn't work when using CloudWatch Events to trigger the pipeline,
as the ID of the generated Event only used the pipeline ID for uniqueness.
Change it to also use the branch name when generating the Event ID
(which cannot be empty, as it turns out, so validate that as well).

Fixes #7802

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@ZakHargz
Copy link

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

@skinny85
Copy link
Contributor

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

@sirmattx
Copy link

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?

@skinny85
Copy link
Contributor

@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?

@sirmattx
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codecommit Related to AWS CodeCommit @aws-cdk/aws-codepipeline Related to AWS CodePipeline bug This issue is a bug. in-progress This issue is being actively worked on. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants