From f6dab8d8c5aa4cf56d6846e2d13c1d5641136f72 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Fri, 21 Jan 2022 02:38:08 +0100 Subject: [PATCH] fix(pipelines): CodeBuild projects are hard to tell apart (#18492) CDK Pipelines generates a number of CodeBuild projects, and they are hard to tell apart some times. Add `Description` fields to each of them. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../lib/codepipeline/_codebuild-factory.ts | 1 + .../test/codepipeline/codebuild-step.test.ts | 22 +++++++++ .../integ.newpipeline-with-vpc.expected.json | 48 +++++++++++++++++++ .../test/integ.newpipeline.expected.json | 24 ++++++++++ .../pipelines/test/testhelpers/matchers.ts | 2 +- 5 files changed, 96 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/pipelines/lib/codepipeline/_codebuild-factory.ts b/packages/@aws-cdk/pipelines/lib/codepipeline/_codebuild-factory.ts index 294a8844b81bb..5d73e23784314 100644 --- a/packages/@aws-cdk/pipelines/lib/codepipeline/_codebuild-factory.ts +++ b/packages/@aws-cdk/pipelines/lib/codepipeline/_codebuild-factory.ts @@ -273,6 +273,7 @@ export class CodeBuildFactory implements ICodePipelineActionFactory { const project = new codebuild.PipelineProject(projectScope, this.constructId, { projectName: this.props.projectName, + description: `Pipeline step ${options.pipeline.pipeline.pipelineName}/${stage.stageName}/${actionName}`, environment, vpc: projectOptions.vpc, subnetSelection: projectOptions.subnetSelection, diff --git a/packages/@aws-cdk/pipelines/test/codepipeline/codebuild-step.test.ts b/packages/@aws-cdk/pipelines/test/codepipeline/codebuild-step.test.ts index c905c3cbc4cfa..01069ee7adee0 100644 --- a/packages/@aws-cdk/pipelines/test/codepipeline/codebuild-step.test.ts +++ b/packages/@aws-cdk/pipelines/test/codepipeline/codebuild-step.test.ts @@ -43,6 +43,28 @@ test('additionalinputs creates the right commands', () => { }); }); +test('CodeBuild projects have a description', () => { + new cdkp.CodePipeline(pipelineStack, 'Pipeline', { + synth: new cdkp.CodeBuildStep('Synth', { + commands: ['/bin/true'], + input: cdkp.CodePipelineSource.gitHub('test/test', 'main'), + }), + }); + + // THEN + Template.fromStack(pipelineStack).hasResourceProperties( + 'AWS::CodeBuild::Project', + { + Description: { + 'Fn::Join': [ + '', + ['Pipeline step ', { Ref: 'Pipeline9850B417' }, '/Build/Synth'], + ], + }, + }, + ); +}); + test('long duration steps are supported', () => { // WHEN new cdkp.CodePipeline(pipelineStack, 'Pipeline', { diff --git a/packages/@aws-cdk/pipelines/test/integ.newpipeline-with-vpc.expected.json b/packages/@aws-cdk/pipelines/test/integ.newpipeline-with-vpc.expected.json index c0d89b2bf135a..1b6de60c8e589 100644 --- a/packages/@aws-cdk/pipelines/test/integ.newpipeline-with-vpc.expected.json +++ b/packages/@aws-cdk/pipelines/test/integ.newpipeline-with-vpc.expected.json @@ -1355,6 +1355,18 @@ "Cache": { "Type": "NO_CACHE" }, + "Description": { + "Fn::Join": [ + "", + [ + "Pipeline step ", + { + "Ref": "Pipeline9850B417" + }, + "/Build/Synth" + ] + ] + }, "EncryptionKey": "alias/aws/s3", "VpcConfig": { "SecurityGroupIds": [ @@ -1942,6 +1954,18 @@ "Cache": { "Type": "NO_CACHE" }, + "Description": { + "Fn::Join": [ + "", + [ + "Pipeline step ", + { + "Ref": "Pipeline9850B417" + }, + "/UpdatePipeline/SelfMutate" + ] + ] + }, "EncryptionKey": "alias/aws/s3", "VpcConfig": { "SecurityGroupIds": [ @@ -2284,6 +2308,18 @@ "Cache": { "Type": "NO_CACHE" }, + "Description": { + "Fn::Join": [ + "", + [ + "Pipeline step ", + { + "Ref": "Pipeline9850B417" + }, + "/Assets/FileAsset1" + ] + ] + }, "EncryptionKey": "alias/aws/s3", "VpcConfig": { "SecurityGroupIds": [ @@ -2385,6 +2421,18 @@ "Cache": { "Type": "NO_CACHE" }, + "Description": { + "Fn::Join": [ + "", + [ + "Pipeline step ", + { + "Ref": "Pipeline9850B417" + }, + "/Assets/FileAsset2" + ] + ] + }, "EncryptionKey": "alias/aws/s3", "VpcConfig": { "SecurityGroupIds": [ diff --git a/packages/@aws-cdk/pipelines/test/integ.newpipeline.expected.json b/packages/@aws-cdk/pipelines/test/integ.newpipeline.expected.json index 6e12dae20df4d..6e8c76b176b7f 100644 --- a/packages/@aws-cdk/pipelines/test/integ.newpipeline.expected.json +++ b/packages/@aws-cdk/pipelines/test/integ.newpipeline.expected.json @@ -2036,6 +2036,18 @@ "Cache": { "Type": "NO_CACHE" }, + "Description": { + "Fn::Join": [ + "", + [ + "Pipeline step ", + { + "Ref": "Pipeline9850B417" + }, + "/Build/Synth" + ] + ] + }, "EncryptionKey": "alias/aws/s3" } }, @@ -2335,6 +2347,18 @@ "Cache": { "Type": "NO_CACHE" }, + "Description": { + "Fn::Join": [ + "", + [ + "Pipeline step ", + { + "Ref": "Pipeline9850B417" + }, + "/UpdatePipeline/SelfMutate" + ] + ] + }, "EncryptionKey": "alias/aws/s3" } } diff --git a/packages/@aws-cdk/pipelines/test/testhelpers/matchers.ts b/packages/@aws-cdk/pipelines/test/testhelpers/matchers.ts index 97a02fc1dc10d..f7ba6458f7449 100644 --- a/packages/@aws-cdk/pipelines/test/testhelpers/matchers.ts +++ b/packages/@aws-cdk/pipelines/test/testhelpers/matchers.ts @@ -26,7 +26,7 @@ class StringLike extends Matcher { public test(actual: any): MatchResult { if (typeof(actual) !== 'string') { - throw new Error(`Expected string but found ${typeof(actual)}`); + throw new Error(`Expected string but found ${typeof(actual)} ${JSON.stringify(actual)}`); } const re = new RegExp(`^${this.pattern.split('*').map(escapeRegex).join('.*')}$`);