-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(codebuild): allow taking the artifact name from the buildspec #7384
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
Changes from 11 commits
eb965d8
d524887
c1f6757
cf6d658
7c171e7
ecef1e7
cc930e6
395d53f
ed1c25b
3906e85
a7f78b9
71ab99c
f5b99c3
dbf6778
8c76e8d
12c9654
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 <build-id> 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 "<path>/<build-id>/<name>" or | ||
| * "<path>/<name>" 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, | ||
|
|
@@ -142,9 +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.name == null ? true : undefined, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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": "awscdkcodebuildbuildspecartifactnameMyProjectACDB7F8B", | ||
| "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" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 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-buildspec-artifact-name'); | ||
|
|
||
| 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, | ||
| includeBuildId: false, | ||
| packageZip: true, | ||
| path: 'another/path', | ||
| identifier: 'AddArtifact1', | ||
| }), | ||
| }); | ||
|
|
||
| app.synth(); |
Uh oh!
There was an error while loading. Please reload this page.