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-actions] Can't use a token for branchName in CodeCommitAction #10263

Closed
alanraison opened this issue Sep 9, 2020 · 2 comments · Fixed by #10463
Closed

[codepipeline-actions] Can't use a token for branchName in CodeCommitAction #10263

alanraison opened this issue Sep 9, 2020 · 2 comments · Fixed by #10463
Assignees
Labels
@aws-cdk/aws-codepipeline-actions bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@alanraison
Copy link
Contributor

alanraison commented Sep 9, 2020

If a token (e.g. a CfnParameter value) is used to define the branchName of the CodeCommit Repository in a CodeCommitAction, synthesis fails with:

Cannot use tokens in construct ID: <PipelineId>-${Token[TOKEN.192]}-EventRule

Reproduction Steps

import { Stack, Construct, StackProps, CfnParameter } from '@aws-cdk/core';
import { Pipeline, Artifact } from '@aws-cdk/aws-codepipeline';
import { CodeCommitSourceAction } from '@aws-cdk/aws-codepipeline-actions';
import { Repository } from '@aws-cdk/aws-codecommit';

export default class FailingPipelineStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const branchName = new CfnParameter(this, 'BranchName', {
      type: 'String',
    });

    const repo = new Repository(this, 'Repository', {
      repositoryName: 'the-repository',
    });

    new Pipeline(this, 'FailingPipeline', {
      stages: [{
        stageName: 'source',
        actions: [
          new CodeCommitSourceAction({
            actionName: 'readSource',
            output: new Artifact('artifact'),
            repository: repo,
            branch: branchName.valueAsString,
          }),
        ],
      }],
    });
  }
}

What did you expect to happen?

Stack is synthesised correctly.

What actually happened?

Stack fails to synthesise with error:

Cannot use tokens in construct ID: DeploymentPipeline145A2410-${Token[TOKEN.192]}-EventRule

Environment

  • CLI Version : 1.62.0
  • Framework Version:
  • Node.js Version: 12.18.3
  • OS : Linux (Debian Buster in Docker)
  • Language (Version): Typescript 3.9.7

Other

I notice that the cause of this is during SourceAction.bound():

if (createEvent) {
    const branchIdDisambiguator = this.branch === 'master' ? '' : `-${this.branch}-`;
    this.props.repository.onCommit(`${stage.pipeline.node.uniqueId}${branchIdDisambiguator}EventRule`, {
        target: new targets.CodePipeline(stage.pipeline),
        branches: [this.branch],
    });
}

this.branch should probably be checked to see if it's a usuable value (i.e. not a token) and if it is unusable as an ID, a random value created.

The workaround is to set trigger: CodeCommitTrigger.NONE and create my own cloudtrail trigger.


This is 🐛 Bug Report

@alanraison alanraison added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 9, 2020
@skinny85
Copy link
Contributor

skinny85 commented Sep 9, 2020

Hey @alanraison ,

thanks for opening the issue. This is very similar to #9575 for S3SourceAction. Need to fix it for CodeCommitSourceAction.

@skinny85 skinny85 added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Sep 9, 2020
@skinny85
Copy link
Contributor

skinny85 commented Sep 9, 2020

@alanraison of course, a Pull Request fixing this would be very welcome 🙂 see here for some tips on how to open us a PR here: https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md

alanraison added a commit to alanraison/aws-cdk that referenced this issue Sep 21, 2020
alanraison added a commit to alanraison/aws-cdk that referenced this issue Sep 21, 2020
When using the EVENTS trigger, an event is created based on the branch name of
the event, however this is not possible if the branch name is an unresolved
value. Therefore generate a unique event name if this is the case.

Fixes aws#10263
@mergify mergify bot closed this as completed in #10463 Sep 22, 2020
mergify bot pushed a commit that referenced this issue Sep 22, 2020
…#10463)

When using the EVENTS trigger, an event is created based on the branch name of 
the event, however this is not possible if the branch name is an unresolved
value. Therefore generate a unique event name if this is the case.

Fixes #10263

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codepipeline-actions bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants