diff --git a/lib/__tests__/auto-build.test.ts b/lib/__tests__/auto-build.test.ts index 8a60f0fd..fa7b6cf3 100644 --- a/lib/__tests__/auto-build.test.ts +++ b/lib/__tests__/auto-build.test.ts @@ -1,5 +1,7 @@ import { App, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; +import { Artifacts } from 'aws-cdk-lib/aws-codebuild'; +import { Bucket } from 'aws-cdk-lib/aws-s3'; import { AutoBuild, GitHubRepo } from '../../lib'; let app: App; @@ -127,3 +129,27 @@ test('can disable webhooks', () => { }, }); }); + +test('can enable artifacts', () => { + new AutoBuild(stack, 'AutoBuild', { + repo: new GitHubRepo({ + repository: 'some-repo', + tokenSecretArn: 'arn:aws:secretsmanager:someregion:someaccount:secret:sometoken', + }), + artifacts: Artifacts.s3({ + bucket: new Bucket(stack, 'artifactBucket'), + name: 'artifact-name', + }), + }); + const template = Template.fromStack(stack); + + template.hasResourceProperties('AWS::CodeBuild::Project', { + Artifacts: { + Location: { Ref: 'artifactBucket27548F83' }, + Name: 'artifact-name', + NamespaceType: 'BUILD_ID', + Packaging: 'ZIP', + Type: 'S3', + }, + }); +}); diff --git a/lib/auto-build.ts b/lib/auto-build.ts index 65bb4717..0c1c55e0 100644 --- a/lib/auto-build.ts +++ b/lib/auto-build.ts @@ -65,6 +65,11 @@ export interface AutoBuildOptions { */ readonly buildSpec?: codebuild.BuildSpec; /* tslint:enable:max-line-length */ + + /** + * ARTIFACTS + */ + readonly artifacts?: codebuild.IArtifacts; } export interface AutoBuildProps extends AutoBuildOptions { @@ -112,6 +117,7 @@ export class AutoBuild extends Construct { environment: createBuildEnvironment(props.environment ?? {}), badge: props.repo.allowsBadge, buildSpec: props.buildSpec, + artifacts: props.artifacts, ssmSessionPermissions: true, }); this.project.role!.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonElasticContainerRegistryPublicReadOnly'));