From eb965d87ec905dea3db8c5f9357834ebbe30e793 Mon Sep 17 00:00:00 2001 From: Alex S Date: Wed, 15 Apr 2020 16:05:32 +0100 Subject: [PATCH 1/8] feat(codebuild): Support OverrideArtifactName on S3BuildProps This commit adds support for CodeBuild Artifacts to have names controlled by a buildspec file, allowing the use of shell scripting to sensibly name artifacts in CodeBuild projects generated from the CDK. Fixes aws#5955 --- .../@aws-cdk/aws-codebuild/lib/artifacts.ts | 9 + ....project-buildspec-artifacts.expected.json | 164 ++++++++++++++++++ .../test/integ.project-buildspec-artifacts.ts | 29 ++++ .../aws-codebuild/test/test.codebuild.ts | 58 ++++++- 4 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json create mode 100644 packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts diff --git a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts index a65e453d7da6a..d1af1c7b16645 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts @@ -121,6 +121,14 @@ export interface S3ArtifactsProps extends ArtifactsProps { * @default true - output will be encrypted */ readonly encryption?: boolean; + + /** + * If this is true, the name defined in the buildspec file will be used for artifacts. + * Otherwise, the artifact will use the property. + * + * @default false - ignore buildspec artifact name + */ + readonly useBuildspecName?: boolean; } /** @@ -145,6 +153,7 @@ class S3Artifacts extends Artifacts { name: this.props.name, packaging: this.props.packageZip === false ? 'NONE' : 'ZIP', encryptionDisabled: this.props.encryption === false ? true : undefined, + overrideArtifactName: this.props.useBuildspecName === true ? true : undefined, } }; } diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json new file mode 100644 index 0000000000000..a0923247c62e5 --- /dev/null +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json @@ -0,0 +1,164 @@ +{ + "Resources": { + "MyBucketF68F3FF0": { + "DeletionPolicy": "Delete", + "UpdateReplacePolicy": "Delete", + "Type": "AWS::S3::Bucket" + }, + "MyProjectRole9BBE5233": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "codebuild.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "MyProjectRoleDefaultPolicyB19B7C29": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "s3:GetObject*", + "s3:GetBucket*", + "s3:List*", + "s3:DeleteObject*", + "s3:PutObject*", + "s3:Abort*" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "MyBucketF68F3FF0", + "Arn" + ] + }, + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "MyBucketF68F3FF0", + "Arn" + ] + }, + "/*" + ] + ] + } + ] + }, + { + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + } + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codebuild/", + { + "Ref": "MyProject39F7B0AE" + }, + ":*" + ] + ] + } + ] + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "MyProjectRoleDefaultPolicyB19B7C29", + "Roles": [ + { + "Ref": "MyProjectRole9BBE5233" + } + ] + } + }, + "MyProject39F7B0AE": { + "Type": "AWS::CodeBuild::Project", + "Properties": { + "Artifacts": { + "ArtifactIdentifier": "AddArtifact1", + "Location": { "Ref": "MyBucketF68F3FF0" }, + "Name": "name", + "NamespaceType": "NONE", + "OverrideArtifactName": true, + "Packaging": "ZIP", + "Path": "another/path", + "Type": "S3" + }, + "Environment": { + "ComputeType": "BUILD_GENERAL1_SMALL", + "Image": "aws/codebuild/standard:1.0", + "PrivilegedMode": false, + "Type": "LINUX_CONTAINER" + }, + "ServiceRole": { + "Fn::GetAtt": [ + "MyProjectRole9BBE5233", + "Arn" + ] + }, + "Source": { + "BuildSpec": "{\n \"version\": \"0.2\"\n}", + "Type": "NO_SOURCE" + } + } + } + } +} + diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts new file mode 100644 index 0000000000000..333729a87efcd --- /dev/null +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts @@ -0,0 +1,29 @@ +import * as s3 from '@aws-cdk/aws-s3'; +import * as cdk from '@aws-cdk/core'; +import * as codebuild from '../lib'; + +const app = new cdk.App(); + +const stack = new cdk.Stack(app, 'aws-cdk-codebuild-secondary-sources-artifacts'); + +const bucket = new s3.Bucket(stack, 'MyBucket', { + removalPolicy: cdk.RemovalPolicy.DESTROY +}); + +new codebuild.Project(stack, 'MyProject', { + buildSpec: codebuild.BuildSpec.fromObject({ + version: '0.2', + }), + artifacts: + codebuild.Artifacts.s3({ + bucket, + name: 'name', + includeBuildId: false, + packageZip: true, + path: 'another/path', + identifier: 'AddArtifact1', + useBuildspecName: true, + }), +}); + +app.synth(); diff --git a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts index a33f14bc29e57..83dd9f6be5441 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts @@ -1,4 +1,4 @@ -import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert'; +import { ABSENT, expect, haveResource, haveResourceLike } from '@aws-cdk/assert'; import * as codecommit from '@aws-cdk/aws-codecommit'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as kms from '@aws-cdk/aws-kms'; @@ -1130,6 +1130,62 @@ export = { } })); + test.done(); + }, + }, + 'S3': { + 'useBuildspecName is set to true'(test: Test) { + const stack = new cdk.Stack(); + const bucket = new s3.Bucket(stack, 'MyBucket'); + new codebuild.Project(stack, 'MyProject', { + source: codebuild.Source.s3({ + bucket, + path: 'some/path', + }), + artifacts: codebuild.Artifacts.s3({ + bucket, + path: 'another/path', + name: 'name', + identifier: 'artifact1', + useBuildspecName: true, + }) + }); + + expect(stack).to(haveResourceLike('AWS::CodeBuild::Project', { + 'Artifacts': + { + 'ArtifactIdentifier': 'artifact1', + 'OverrideArtifactName': true, + }, + })); + + test.done(); + }, + 'useBuildspecName is set to false'(test: Test) { + const stack = new cdk.Stack(); + const bucket = new s3.Bucket(stack, 'MyBucket'); + new codebuild.Project(stack, 'MyProject', { + source: codebuild.Source.s3({ + bucket, + path: 'some/path', + }), + artifacts: codebuild.Artifacts.s3({ + bucket, + path: 'another/path', + name: 'name', + identifier: 'artifact1', + useBuildspecName: false, + }) + }); + + expect(stack).to(haveResourceLike('AWS::CodeBuild::Project', { + 'Artifacts': + { + 'ArtifactIdentifier': 'artifact1', + 'OverrideArtifactName': ABSENT + }, + })); + test.done(); }, }, From d5248871c2af4579620fed5a1899ad674396ce0f Mon Sep 17 00:00:00 2001 From: shearna Date: Thu, 16 Apr 2020 12:56:46 +0100 Subject: [PATCH 2/8] Updating README for package --- packages/@aws-cdk/aws-codebuild/README.md | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-codebuild/README.md b/packages/@aws-cdk/aws-codebuild/README.md index 0b28d65d992e8..8517c7e4405c5 100644 --- a/packages/@aws-cdk/aws-codebuild/README.md +++ b/packages/@aws-cdk/aws-codebuild/README.md @@ -273,6 +273,33 @@ const rule = project.onStateChange('BuildStateChange', { }); ``` +## Artifacts + +CodeBuild Projects can produce Artifacts and upload the to S3. For example: + +```ts +const project = codebuild.Project(stack, 'MyProject', { + buildSpec: codebuild.BuildSpec.fromObject({ + version: '0.2', + }), + artifacts: + codebuild.Artifacts.s3({ + bucket, + name: 'name', + includeBuildId: false, + packageZip: true, + path: 'another/path', + identifier: 'AddArtifact1', + useBuildspecName: true, + }), +}); +``` + +This example will produce an artifact named as defined in the Buildspec file, +uploaded to an S3 bucket (`bucket`). The path will be `another/path` and the +artifact will be a zipfile. In this case, the `name` parameter will be ignored +by CodeBuild in favour of that specified in the `buildspec.yml`. + ## Secondary sources and artifacts CodeBuild Projects can get their sources from multiple places, and produce @@ -409,4 +436,4 @@ new codebuild.Project(stack, 'MyProject', { Here's a CodeBuild project with a simple example that creates a project mounted on AWS EFS: -[Minimal Example](./test/integ.project-file-system-location.ts) \ No newline at end of file +[Minimal Example](./test/integ.project-file-system-location.ts) From c1f6757b1c894493701ccd1bbdd76313a4204983 Mon Sep 17 00:00:00 2001 From: shearna Date: Thu, 16 Apr 2020 13:03:16 +0100 Subject: [PATCH 3/8] Fixing trailing whitespace --- packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts index 83dd9f6be5441..050299c0cb2e3 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts @@ -1152,7 +1152,7 @@ export = { }); expect(stack).to(haveResourceLike('AWS::CodeBuild::Project', { - 'Artifacts': + 'Artifacts': { 'ArtifactIdentifier': 'artifact1', 'OverrideArtifactName': true, From 395d53f90cbc94017990d6c710b8e19c170cb48b Mon Sep 17 00:00:00 2001 From: shearn89 Date: Sun, 26 Apr 2020 13:11:52 +0100 Subject: [PATCH 4/8] Fixing lint errors --- packages/@aws-cdk/aws-codebuild/lib/artifacts.ts | 2 +- .../aws-codebuild/test/integ.project-buildspec-artifacts.ts | 2 +- packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts index d1af1c7b16645..4df9a00872109 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts @@ -154,7 +154,7 @@ class S3Artifacts extends Artifacts { packaging: this.props.packageZip === false ? 'NONE' : 'ZIP', encryptionDisabled: this.props.encryption === false ? true : undefined, overrideArtifactName: this.props.useBuildspecName === true ? true : undefined, - } + }, }; } } diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts index 333729a87efcd..5b3714acbb7ae 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts @@ -7,7 +7,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-cdk-codebuild-secondary-sources-artifacts'); const bucket = new s3.Bucket(stack, 'MyBucket', { - removalPolicy: cdk.RemovalPolicy.DESTROY + removalPolicy: cdk.RemovalPolicy.DESTROY, }); new codebuild.Project(stack, 'MyProject', { diff --git a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts index 2e84278bfa1f1..dd2aee893e676 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts @@ -1148,7 +1148,7 @@ export = { name: 'name', identifier: 'artifact1', useBuildspecName: true, - }) + }), }); expect(stack).to(haveResourceLike('AWS::CodeBuild::Project', { @@ -1175,14 +1175,14 @@ export = { name: 'name', identifier: 'artifact1', useBuildspecName: false, - }) + }), }); expect(stack).to(haveResourceLike('AWS::CodeBuild::Project', { 'Artifacts': { 'ArtifactIdentifier': 'artifact1', - 'OverrideArtifactName': ABSENT + 'OverrideArtifactName': ABSENT, }, })); From ed1c25b68cd4317f5c499b6744eeab39380d7599 Mon Sep 17 00:00:00 2001 From: shearn89 Date: Tue, 28 Apr 2020 14:53:28 +0100 Subject: [PATCH 5/8] Updated with review comments from @skinny85 --- packages/@aws-cdk/aws-codebuild/README.md | 54 +++++++++---------- .../@aws-cdk/aws-codebuild/lib/artifacts.ts | 4 +- .../test/integ.project-buildspec-artifacts.ts | 2 +- .../aws-codebuild/test/test.codebuild.ts | 8 +-- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/packages/@aws-cdk/aws-codebuild/README.md b/packages/@aws-cdk/aws-codebuild/README.md index 8517c7e4405c5..9f4793a4d84e1 100644 --- a/packages/@aws-cdk/aws-codebuild/README.md +++ b/packages/@aws-cdk/aws-codebuild/README.md @@ -115,6 +115,33 @@ const bbSource = codebuild.Source.bitBucket({ }); ``` +## Artifacts + +CodeBuild Projects can produce Artifacts and upload the to S3. For example: + +```ts +const project = codebuild.Project(stack, 'MyProject', { + buildSpec: codebuild.BuildSpec.fromObject({ + version: '0.2', + }), + artifacts: codebuild.Artifacts.s3({ + bucket, + name: 'name', + includeBuildId: false, + packageZip: true, + path: 'another/path', + identifier: 'AddArtifact1', + useBuildspecName: true, + }), +}); +``` + +This example will produce an artifact named as defined in the Buildspec file, +uploaded to an S3 bucket (`bucket`). The path will be `another/path` and the +artifact will be a zipfile. In this case, the `name` parameter will be ignored +by CodeBuild in favour of that specified in the `buildspec.yml`. + + ## CodePipeline To add a CodeBuild Project as an Action to CodePipeline, @@ -273,33 +300,6 @@ const rule = project.onStateChange('BuildStateChange', { }); ``` -## Artifacts - -CodeBuild Projects can produce Artifacts and upload the to S3. For example: - -```ts -const project = codebuild.Project(stack, 'MyProject', { - buildSpec: codebuild.BuildSpec.fromObject({ - version: '0.2', - }), - artifacts: - codebuild.Artifacts.s3({ - bucket, - name: 'name', - includeBuildId: false, - packageZip: true, - path: 'another/path', - identifier: 'AddArtifact1', - useBuildspecName: true, - }), -}); -``` - -This example will produce an artifact named as defined in the Buildspec file, -uploaded to an S3 bucket (`bucket`). The path will be `another/path` and the -artifact will be a zipfile. In this case, the `name` parameter will be ignored -by CodeBuild in favour of that specified in the `buildspec.yml`. - ## Secondary sources and artifacts CodeBuild Projects can get their sources from multiple places, and produce diff --git a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts index 4df9a00872109..8b70b701dbae8 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts @@ -128,7 +128,7 @@ export interface S3ArtifactsProps extends ArtifactsProps { * * @default false - ignore buildspec artifact name */ - readonly useBuildspecName?: boolean; + readonly useNameFromBuildSpec?: boolean; } /** @@ -153,7 +153,7 @@ class S3Artifacts extends Artifacts { name: this.props.name, packaging: this.props.packageZip === false ? 'NONE' : 'ZIP', encryptionDisabled: this.props.encryption === false ? true : undefined, - overrideArtifactName: this.props.useBuildspecName === true ? true : undefined, + overrideArtifactName: this.props.useNameFromBuildSpec === true ? true : undefined, }, }; } diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts index 5b3714acbb7ae..1d057287e50b8 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts @@ -22,7 +22,7 @@ new codebuild.Project(stack, 'MyProject', { packageZip: true, path: 'another/path', identifier: 'AddArtifact1', - useBuildspecName: true, + useNameFromBuildSpec: true, }), }); diff --git a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts index dd2aee893e676..d16d0b09f0efe 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts @@ -1134,7 +1134,7 @@ export = { }, }, 'S3': { - 'useBuildspecName is set to true'(test: Test) { + 'useNameFromBuildSpec is set to true'(test: Test) { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); new codebuild.Project(stack, 'MyProject', { @@ -1147,7 +1147,7 @@ export = { path: 'another/path', name: 'name', identifier: 'artifact1', - useBuildspecName: true, + useNameFromBuildSpec: true, }), }); @@ -1161,7 +1161,7 @@ export = { test.done(); }, - 'useBuildspecName is set to false'(test: Test) { + 'useNameFromBuildSpec is set to false'(test: Test) { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); new codebuild.Project(stack, 'MyProject', { @@ -1174,7 +1174,7 @@ export = { path: 'another/path', name: 'name', identifier: 'artifact1', - useBuildspecName: false, + useNameFromBuildSpec: false, }), }); From 3906e857445ed969b193b4d7125b11cf15d9f8a5 Mon Sep 17 00:00:00 2001 From: shearn89 Date: Tue, 28 Apr 2020 15:37:27 +0100 Subject: [PATCH 6/8] Updating PR with design comments This commit reworks the implementation to instead make `name` optional. If the `name` is not provided, `overrideArtifactName` will be set and the buildspec name will be used. --- packages/@aws-cdk/aws-codebuild/README.md | 11 ++++------ .../@aws-cdk/aws-codebuild/lib/artifacts.ts | 21 +++++++++---------- ....project-buildspec-artifacts.expected.json | 2 +- .../test/integ.project-buildspec-artifacts.ts | 4 +--- .../aws-codebuild/test/test.codebuild.ts | 7 ++----- 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/packages/@aws-cdk/aws-codebuild/README.md b/packages/@aws-cdk/aws-codebuild/README.md index 9f4793a4d84e1..c5e534fdadf42 100644 --- a/packages/@aws-cdk/aws-codebuild/README.md +++ b/packages/@aws-cdk/aws-codebuild/README.md @@ -126,21 +126,18 @@ const project = codebuild.Project(stack, 'MyProject', { }), artifacts: codebuild.Artifacts.s3({ bucket, - name: 'name', includeBuildId: false, packageZip: true, path: 'another/path', identifier: 'AddArtifact1', - useBuildspecName: true, }), }); ``` -This example will produce an artifact named as defined in the Buildspec file, -uploaded to an S3 bucket (`bucket`). The path will be `another/path` and the -artifact will be a zipfile. In this case, the `name` parameter will be ignored -by CodeBuild in favour of that specified in the `buildspec.yml`. - +Because we've not set the `name` property, this example will set the +`overrideArtifactName` parameter, and produce an artifact named as defined in +the Buildspec file, uploaded to an S3 bucket (`bucket`). The path will be +`another/path` and the artifact will be a zipfile. ## CodePipeline diff --git a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts index 8b70b701dbae8..a556a0f459c89 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts @@ -87,6 +87,8 @@ export interface S3ArtifactsProps extends ArtifactsProps { * The path inside of the bucket for the build output .zip file or folder. * If a value is not specified, then build output will be stored at the root of the * bucket (or under the directory if `includeBuildId` is set to true). + * + * @default the root of the bucket */ readonly path?: string; @@ -95,8 +97,13 @@ export interface S3ArtifactsProps extends ArtifactsProps { * * The full S3 object key will be "//" or * "/" depending on whether `includeBuildId` is set to true. + * + * If not set, `overrideArtifactName` will be set and the name from the + * buildspec will be used instead. + * + * @default the unique ID of the project node */ - readonly name: string; + readonly name?: string; /** * Indicates if the build ID should be included in the path. If this is set to true, @@ -121,14 +128,6 @@ export interface S3ArtifactsProps extends ArtifactsProps { * @default true - output will be encrypted */ readonly encryption?: boolean; - - /** - * If this is true, the name defined in the buildspec file will be used for artifacts. - * Otherwise, the artifact will use the property. - * - * @default false - ignore buildspec artifact name - */ - readonly useNameFromBuildSpec?: boolean; } /** @@ -150,10 +149,10 @@ class S3Artifacts extends Artifacts { location: this.props.bucket.bucketName, path: this.props.path, namespaceType: this.props.includeBuildId === false ? 'NONE' : 'BUILD_ID', - name: this.props.name, + name: this.props.name == null ? project.node.uniqueId : this.props.name, packaging: this.props.packageZip === false ? 'NONE' : 'ZIP', encryptionDisabled: this.props.encryption === false ? true : undefined, - overrideArtifactName: this.props.useNameFromBuildSpec === true ? true : undefined, + overrideArtifactName: this.props.name == null ? true : undefined, }, }; } diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json index a0923247c62e5..11a576add1691 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json @@ -134,7 +134,7 @@ "Artifacts": { "ArtifactIdentifier": "AddArtifact1", "Location": { "Ref": "MyBucketF68F3FF0" }, - "Name": "name", + "Name": "awscdkcodebuildbuildspecartifactnameMyProjectACDB7F8B", "NamespaceType": "NONE", "OverrideArtifactName": true, "Packaging": "ZIP", diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts index 1d057287e50b8..6cf42d7a3e102 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.ts @@ -4,7 +4,7 @@ import * as codebuild from '../lib'; const app = new cdk.App(); -const stack = new cdk.Stack(app, 'aws-cdk-codebuild-secondary-sources-artifacts'); +const stack = new cdk.Stack(app, 'aws-cdk-codebuild-buildspec-artifact-name'); const bucket = new s3.Bucket(stack, 'MyBucket', { removalPolicy: cdk.RemovalPolicy.DESTROY, @@ -17,12 +17,10 @@ new codebuild.Project(stack, 'MyProject', { artifacts: codebuild.Artifacts.s3({ bucket, - name: 'name', includeBuildId: false, packageZip: true, path: 'another/path', identifier: 'AddArtifact1', - useNameFromBuildSpec: true, }), }); diff --git a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts index d16d0b09f0efe..1947ae487744e 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts @@ -1134,7 +1134,7 @@ export = { }, }, 'S3': { - 'useNameFromBuildSpec is set to true'(test: Test) { + 'name is not set so use buildspec'(test: Test) { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); new codebuild.Project(stack, 'MyProject', { @@ -1145,9 +1145,7 @@ export = { artifacts: codebuild.Artifacts.s3({ bucket, path: 'another/path', - name: 'name', identifier: 'artifact1', - useNameFromBuildSpec: true, }), }); @@ -1161,7 +1159,7 @@ export = { test.done(); }, - 'useNameFromBuildSpec is set to false'(test: Test) { + 'name is set so use it'(test: Test) { const stack = new cdk.Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); new codebuild.Project(stack, 'MyProject', { @@ -1174,7 +1172,6 @@ export = { path: 'another/path', name: 'name', identifier: 'artifact1', - useNameFromBuildSpec: false, }), }); From 71ab99cb2af5b05251379ccc0161b343c3a56b81 Mon Sep 17 00:00:00 2001 From: Alex Shearn Date: Wed, 29 Apr 2020 08:20:09 +0100 Subject: [PATCH 7/8] Update packages/@aws-cdk/aws-codebuild/README.md Fixing typo. Co-Authored-By: Adam Ruka --- packages/@aws-cdk/aws-codebuild/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-codebuild/README.md b/packages/@aws-cdk/aws-codebuild/README.md index c8a678b0982e8..392e6a124e767 100644 --- a/packages/@aws-cdk/aws-codebuild/README.md +++ b/packages/@aws-cdk/aws-codebuild/README.md @@ -117,7 +117,7 @@ const bbSource = codebuild.Source.bitBucket({ ## Artifacts -CodeBuild Projects can produce Artifacts and upload the to S3. For example: +CodeBuild Projects can produce Artifacts and upload them to S3. For example: ```ts const project = codebuild.Project(stack, 'MyProject', { From f5b99c333136f022039f66b87f79a153457ba549 Mon Sep 17 00:00:00 2001 From: shearn89 Date: Wed, 29 Apr 2020 08:35:12 +0100 Subject: [PATCH 8/8] Setting name property to undefined rather than specifying the project node id --- packages/@aws-cdk/aws-codebuild/lib/artifacts.ts | 4 ++-- .../test/integ.project-buildspec-artifacts.expected.json | 1 - packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts index a556a0f459c89..eda705fe16860 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/artifacts.ts @@ -101,7 +101,7 @@ export interface S3ArtifactsProps extends ArtifactsProps { * If not set, `overrideArtifactName` will be set and the name from the * buildspec will be used instead. * - * @default the unique ID of the project node + * @default undefined, and use the name from the buildspec */ readonly name?: string; @@ -149,7 +149,7 @@ class S3Artifacts extends Artifacts { location: this.props.bucket.bucketName, path: this.props.path, namespaceType: this.props.includeBuildId === false ? 'NONE' : 'BUILD_ID', - name: this.props.name == null ? project.node.uniqueId : this.props.name, + name: this.props.name == null ? undefined : this.props.name, packaging: this.props.packageZip === false ? 'NONE' : 'ZIP', encryptionDisabled: this.props.encryption === false ? true : undefined, overrideArtifactName: this.props.name == null ? true : undefined, diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json index 11a576add1691..fff6b92d11f44 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json +++ b/packages/@aws-cdk/aws-codebuild/test/integ.project-buildspec-artifacts.expected.json @@ -134,7 +134,6 @@ "Artifacts": { "ArtifactIdentifier": "AddArtifact1", "Location": { "Ref": "MyBucketF68F3FF0" }, - "Name": "awscdkcodebuildbuildspecartifactnameMyProjectACDB7F8B", "NamespaceType": "NONE", "OverrideArtifactName": true, "Packaging": "ZIP", diff --git a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts index 1947ae487744e..29cf00c193719 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts @@ -1152,6 +1152,7 @@ export = { expect(stack).to(haveResourceLike('AWS::CodeBuild::Project', { 'Artifacts': { + 'Name': ABSENT, 'ArtifactIdentifier': 'artifact1', 'OverrideArtifactName': true, }, @@ -1170,7 +1171,7 @@ export = { artifacts: codebuild.Artifacts.s3({ bucket, path: 'another/path', - name: 'name', + name: 'specificname', identifier: 'artifact1', }), }); @@ -1179,6 +1180,7 @@ export = { 'Artifacts': { 'ArtifactIdentifier': 'artifact1', + 'Name': 'specificname', 'OverrideArtifactName': ABSENT, }, }));