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

fix(pipelines): using the same repo more than once as a connection in a pipeline causes duplicate id error #27408

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class GitHubSource extends CodePipelineSource {
private readonly authentication: SecretValue;

constructor(repoString: string, readonly branch: string, readonly props: GitHubSourceOptions) {
super(repoString);
super(`${repoString}-${branch}`);

const parts = repoString.split('/');
if (Token.isUnresolved(repoString) || parts.length !== 2) {
Expand Down Expand Up @@ -312,7 +312,7 @@ export interface S3SourceOptions {

class S3Source extends CodePipelineSource {
constructor(readonly bucket: IBucket, private readonly objectKey: string, readonly props: S3SourceOptions) {
super(Node.of(bucket).addr);
super(`${Node.of(bucket).addr}-${objectKey}`);

this.configurePrimaryOutput(new FileSet('Source', this));
}
Expand Down Expand Up @@ -422,7 +422,7 @@ class CodeStarConnectionSource extends CodePipelineSource {
private readonly repo: string;

constructor(repoString: string, readonly branch: string, readonly props: ConnectionSourceOptions) {
super(repoString);
super(`${repoString}-${branch}`);

const parts = repoString.split('/');
if (Token.isUnresolved(repoString) || parts.length !== 2) {
Expand Down Expand Up @@ -492,8 +492,8 @@ export interface CodeCommitSourceOptions {
class CodeCommitSource extends CodePipelineSource {
constructor(private readonly repository: codecommit.IRepository, private readonly branch: string, private readonly props: CodeCommitSourceOptions) {
super(Token.isUnresolved(repository.repositoryName)
? Node.of(repository).addr
: repository.repositoryName);
? `${Node.of(repository).addr}-${branch}`
: `${repository.repositoryName}-${branch}`);

this.configurePrimaryOutput(new FileSet('Source', this));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as codecommit from '../../../aws-codecommit';
import * as cdk from '../../../core';
import { Stack } from '../../../core';
import { CodeBuildStep, CodePipeline, CodePipelineSource } from '../../../pipelines';

let app: cdk.App = new cdk.App();

const stack = new Stack(app, 'PipeStack', {});

// CodeCommit repo
const repo = new codecommit.Repository(stack, 'WorkshopRepositoryMain', {
repositoryName: 'WorkshopRepoMain',
});

const codeCommitPipeline = new CodePipeline(stack, 'CodeCommitPipeline', {
pipelineName: 'WorkshopPipelineName1',
synth: new CodeBuildStep('SynthStep1', {
input: CodePipelineSource.codeCommit(repo, 'b1', {
actionName: 'branch1',
}),
additionalInputs: {
'source-test-branch': CodePipelineSource.codeCommit(repo, 'b2', {
actionName: 'branch2',
}),
'other-branch': CodePipelineSource.codeCommit(repo, 'b3', {
actionName: 'branch3',
}),
},
installCommands: [
'npm install -g aws-cdk',
],
commands: [
'npm ci',
'npm run build',
'cdk synth',
],
}),
});

test('codeCommit synths', () => {
const assembly = app.synth();
expect(assembly.stacks.length).toEqual(1);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as cdk from '../../../core';
import { Stack } from '../../../core';
import { CodeBuildStep, CodePipeline, CodePipelineSource } from '../../../pipelines';

let app: cdk.App = new cdk.App();

const stack = new Stack(app, 'PipeStack', {});

const connectionPipeline = new CodePipeline(stack, 'ConnectionPipeline', {
pipelineName: 'ConnectionPipeline1',
synth: new CodeBuildStep('SynthStep1', {
input: CodePipelineSource.connection('me/rep', 'b1', {
connectionArn: 'arn:aws:codestar-connections:us-east-1:123456789012:connection/01234567-abcd-12ab-34cdef5678gh',
actionName: 'branch1',
}),
additionalInputs: {
'source-test-branch': CodePipelineSource.connection('me/rep', 'b2', {
connectionArn: 'arn:aws:codestar-connections:us-east-1:123456789012:connection/01234568-abcd-12ab-34cdef5678gh',
actionName: 'branch2',
}),
'other-branch': CodePipelineSource.connection('me/rep', 'b3', {
connectionArn: 'arn:aws:codestar-connections:us-east-1:123456789012:connection/90123456-abcd-12ab-34cdef5678gh',
actionName: 'branch3',
}),
},
installCommands: [
'npm install -g aws-cdk',
],
commands: [
'npm ci',
'npm run build',
'cdk synth',
],
}),
});

test('connection synths', () => {
const assembly = app.synth();
expect(assembly.stacks.length).toEqual(1);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as cdk from '../../../core';
import { Stack } from '../../../core';
import { CodeBuildStep, CodePipeline, CodePipelineSource } from '../../../pipelines';

let app: cdk.App = new cdk.App();

const stack = new Stack(app, 'PipeStack', {});

const githubPipeline = new CodePipeline(stack, 'GithubPipeline', {
pipelineName: 'GithubPipeline1',
synth: new CodeBuildStep('SynthStep1', {
input: CodePipelineSource.gitHub('me/rep', 'b1', {
actionName: 'branch1',
}),
additionalInputs: {
'source-test-branch': CodePipelineSource.gitHub('me/rep', 'b2', {
actionName: 'branch2',
}),
'other-branch': CodePipelineSource.gitHub('me/rep', 'b3', {
actionName: 'branch3',
}),
},
installCommands: [
'npm install -g aws-cdk',
],
commands: [
'npm ci',
'npm run build',
'cdk synth',
],
}),
});

test('github synths', () => {
const assembly = app.synth();
expect(assembly.stacks.length).toEqual(1);
});
Loading