-
Notifications
You must be signed in to change notification settings - Fork 4k
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
(pipelines): using the same repo more than once as a connection in a pipeline causes duplicate id error #23916
Comments
I believe I'm having the same issue when trying to do exactly what OP is. Except my issue comes from executing cdk synth with a .ts pipeline definition.
|
I've looked into this a bit, and it makes sense that this is happening. Thanks for reporting this!
aws-cdk/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline-source.ts Lines 412 to 413 in 1d7aff5
aws-cdk/packages/@aws-cdk/pipelines/lib/blueprint/step.ts Lines 46 to 48 in 1d7aff5
We might want to take the branch name into account here (might be a breaking change), or, we might want to find some way to identify this scenario and adjust the id if so. |
@peterwoodworth thanks for replying, i appreciate it, i'd suggest to have the branch name not to be used as the logical name, cause i think that is what's happening here (and please correct me if im wrong, i just started CDK not long ago), here is my suggestion
That way it would allow checking out the same repo with multiple branches, also out of curiosity are you working for AWS? |
I believe there's an additional parameter,
which should probably be used for the id if provided in the constructor. Unfortunately only the repo string is passed. There was a similar comment provided here : This is problematic, as several folks have mentioned, because you can't create a CodePipeline source for different branches of the same repo. |
I just hit this issue after a major refactor to upgrade all our packages and to finally get our deployments back up to speed. We were using GitHub Version 1 and upgraded to the CodeStarConnections and we can not longer deploy our environment pipelines that relied on a strict branch naming convention. Any idea when this fix will be available? |
… in a pipeline causes duplicate id error (#27602) Differentiates between sources of the same repository by appending the branch name onto the node id and input/output artifacts. This avoids the duplicate id errors for different branches of the same repository, as well as validating that each source is a unique repository & branch combination. The only change to the CFN template is the input & output artifacts, but since these are not stateful resources, they can be modified without breaking changes. The artifacts are also updates in tandem, so the pipeline source behavior will stay the same. This change impacts these `CodePipelineSource`s: - `s3()` - `objectKey` appended - `connection()` - `codeCommit()` Does not change `ecr()` behavior as there is no notion of folders or branches. Does not change `github()` behavior as doing so would cause destructive changes of webhooks. Closes #23916 and #19875. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
This issue being closed with the last mention being a merged PR is thoroughly misleading. The merged fix was reverted 6 days later: History: https://github.com/aws/aws-cdk/commits/main/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.ts Apparently nobody has tried fixing it again since, and this remains an issue. But it seems it would have been easy enough to fix -- at least for those without tokens in their branch names -- by adding the appropriate amount of Roll your own as a workaround: // replace
// CodePipelineSource.connection(`${owner}/${repository}`, branch, { ... });
// with
// new ConnectionSource27602(`${owner}/${repository}`, branch, { ... });
import { Token } from 'aws-cdk-lib';
import { Artifact } from 'aws-cdk-lib/aws-codepipeline';
import { CodeStarConnectionsSourceAction } from 'aws-cdk-lib/aws-codepipeline-actions';
import { CodePipelineSource, ConnectionSourceOptions, FileSet } from 'aws-cdk-lib/pipelines';
// workaround for https://github.com/aws/aws-cdk/issues/23916
// Based on
// https://github.com/aws/aws-cdk/blob/10357c0ab6be105e0d988b9045bcfe99faf69cbd/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.ts#L420
// and
// https://github.com/aws/aws-cdk/blob/70acc844e2a652aea4f1328e4e758c3c5030d501/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.ts#L420
export class ConnectionSource27602 extends CodePipelineSource {
private readonly owner: string;
private readonly repo: string;
constructor(
repoString: string,
readonly branch: string,
readonly props: ConnectionSourceOptions,
) {
super(`${repoString}-${ConnectionSource27602.validateBranch(branch)}`);
if (!this.isValidRepoString(repoString)) {
throw new Error(
`Connection repository name should be a resolved string like '<owner>/<repo>' or '<owner>/<group1>/<group2>/.../<repo>', got '${repoString}'`,
);
}
const parts = repoString.split('/');
this.owner = parts[0];
this.repo = parts.slice(1).join('/');
this.configurePrimaryOutput(new FileSet('Source', this));
}
private static validateBranch(branch: string): string {
if (Token.isUnresolved(branch)) {
throw new Error(`Connection branch name should be a resolved string', got '${branch}'`);
}
return branch;
}
private isValidRepoString(repoString: string) {
if (Token.isUnresolved(repoString)) {
return false;
}
const parts = repoString.split('/');
// minimum length is 2 (owner/repo) and
// maximum length is 22 (owner/parent group/twenty sub groups/repo).
// maximum length is based on limitation of GitLab, see https://docs.gitlab.com/ee/user/group/subgroups/
if (parts.length < 2 || parts.length > 23) {
return false;
}
// check if all element in parts is not empty
return parts.every((element) => element !== '');
}
protected getAction(
output: Artifact,
actionName: string,
runOrder: number,
variablesNamespace?: string,
) {
return new CodeStarConnectionsSourceAction({
output,
actionName: this.props.actionName ?? actionName,
runOrder,
connectionArn: this.props.connectionArn,
owner: this.owner,
repo: this.repo,
branch: this.branch,
codeBuildCloneOutput: this.props.codeBuildCloneOutput,
triggerOnPush: this.props.triggerOnPush,
variablesNamespace,
});
}
} |
Describe the bug
I'm trying to check out two different branches of the same repo, but are getting the "Node with duplicate id" error message. Below is the code that I have
Expected Behavior
I'm expecting CDK will checkout the code from the same repo except it will use different branch and synth the code as usual
Current Behavior
Reproduction Steps
Possible Solution
No response
Additional Information/Context
If you try to change the
source-2
repo name frommy-repo1
tomy-repo2
for example it would work. I think there is a bug here where CDK is reading that line asNode ID
instead ofrepo name
CDK CLI Version
2.51.0 (build a87259f)
Framework Version
No response
Node.js Version
16.18.0
OS
Windows
Language
Python
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: