-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Describe the bug
GitLab repositories that are nested under at least one group cannot be directly with CodePipelineSource.connection
as it limits repositories to the form <owner>/<repo>
. GitLab includes the group names in the repository string, falling outside this format (i.e. owner/group1/group2/groupN/repo
).
Expected Behavior
I expect the pipeline to synthesize successfully when sourcing from a CodePipelineSource.connection
that references a GitLab repository nested under multiple groups.
Current Behavior
The following error is thrown:
Error: CodeStar repository name should be a resolved string like '<owner>/<repo>', got 'owner/group1/group2/repo'
This error is from aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.ts
line 429.
Reproduction Steps
import * as cdk from 'aws-cdk-lib';
import { CodePipeline, CodePipelineSource, ShellStep } from 'aws-cdk-lib/pipelines';
import { Construct } from 'constructs';
class DummyStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
}
}
class DummyApplication extends cdk.Stage {
constructor(scope: Construct, id: string, props?: cdk.StageProps) {
super(scope, id, props);
new DummyStack(this, 'Dummy');
}
}
export class PipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const pipeline = new CodePipeline(this, 'Pipeline', {
synth: new ShellStep("Synthesize", {
input: CodePipelineSource.connection('owner/group/repo', 'main', {
connectionArn: 'arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41',
}),
commands: [
'npm ci',
'npm run build',
'npx cdk synth',
],
}),
});
pipeline.addStage(new DummyApplication(this, 'DummyApp'));
}
}
Possible Solution
--- a/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.ts
+++ b/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.ts
@@ -425,11 +425,11 @@ class CodeStarConnectionSource extends CodePipelineSource
{
super(repoString);
const parts = repoString.split('/');
- if (Token.isUnresolved(repoString) || parts.length !== 2) {
+ if (Token.isUnresolved(repoString) || parts.length < 2) {
throw new Error(`CodeStar repository name should be a resolved string like '<owner>/<repo>', got '${repoString}'`);
}
this.owner = parts[0];
- this.repo = parts[1];
+ this.repo = parts.slice(1).join('/');
this.configurePrimaryOutput(new FileSet('Source', this));
}
Additional Information/Context
No response
CDK CLI Version
2.100.0 (build e1b5c77)
Framework Version
No response
Node.js Version
v18.17.1
OS
Ubuntu 20.04.6 LTS
Language
Python
Language Version
Python 3.8.10
Other information
As a workaround until this is fixed, you can manually re-implement CodeStarConnectionSource
to include the above changes and instantiate directly.