From 3dcd1a8345a20caad5100f810517f8e742bd65e8 Mon Sep 17 00:00:00 2001 From: Tom Jenkinson Date: Thu, 3 Dec 2020 00:35:43 +0000 Subject: [PATCH] feat(codepipeline-actions): support `executeBatchBuild` on `CodeBuildAction` (#11741) See [this doc](https://docs.aws.amazon.com/codebuild/latest/userguide/sample-pipeline-batch.html) which says >To enable batch builds in CodePipeline, set the BatchEnabled parameter of the configuration object to true. The configuration object it is referring to is [this](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codepipeline-pipeline-stages-actions.html#cfn-codepipeline-pipeline-stages-actions-configuration). I didn't add a test to ensure that `BatchEnabled` is not present by default because I wasn't sure exactly how to do this. Let me know if this is needed. It looks like `haveResourceLike` can take a function on `properties`, so maybe it's doable with that? Closes #11662 --- .../aws-codepipeline-actions/README.md | 1 + .../lib/codebuild/build-action.ts | 10 ++++ .../test/codebuild/test.codebuild-action.ts | 55 +++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/packages/@aws-cdk/aws-codepipeline-actions/README.md b/packages/@aws-cdk/aws-codepipeline-actions/README.md index b84b9e574d8e5..ac6db2b9fab00 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/README.md +++ b/packages/@aws-cdk/aws-codepipeline-actions/README.md @@ -311,6 +311,7 @@ const buildAction = new codepipeline_actions.CodeBuildAction({ project, input: sourceOutput, outputs: [new codepipeline.Artifact()], // optional + executeBatchBuild: true // optional, defaults to false }); new codepipeline.Pipeline(this, 'MyPipeline', { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/lib/codebuild/build-action.ts b/packages/@aws-cdk/aws-codepipeline-actions/lib/codebuild/build-action.ts index cedc1db5ca90b..e81095b746eee 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/lib/codebuild/build-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/lib/codebuild/build-action.ts @@ -77,6 +77,13 @@ export interface CodeBuildActionProps extends codepipeline.CommonAwsActionProps * @default - No additional environment variables are specified. */ readonly environmentVariables?: { [name: string]: codebuild.BuildEnvironmentVariable }; + + /** + * Trigger a batch build. + * + * @default false + */ + readonly executeBatchBuild?: boolean; } /** @@ -176,6 +183,9 @@ export class CodeBuildAction extends Action { // lazy, because the Artifact name might be generated lazily configuration.PrimarySource = cdk.Lazy.string({ produce: () => this.props.input.artifactName }); } + if (this.props.executeBatchBuild) { + configuration.BatchEnabled = 'true'; + } return { configuration, }; diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/codebuild/test.codebuild-action.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/codebuild/test.codebuild-action.ts index 3dc54909d8f53..f5d5abaeb4934 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/codebuild/test.codebuild-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/codebuild/test.codebuild-action.ts @@ -202,5 +202,60 @@ export = { test.done(); }, + + 'sets the BatchEnabled configuration'(test: Test) { + const stack = new Stack(); + + const codeBuildProject = new codebuild.PipelineProject(stack, 'CodeBuild'); + + const sourceOutput = new codepipeline.Artifact(); + new codepipeline.Pipeline(stack, 'Pipeline', { + stages: [ + { + stageName: 'Source', + actions: [ + new cpactions.S3SourceAction({ + actionName: 'S3_Source', + bucket: new s3.Bucket(stack, 'Bucket'), + bucketKey: 'key', + output: sourceOutput, + }), + ], + }, + { + stageName: 'Build', + actions: [ + new cpactions.CodeBuildAction({ + actionName: 'CodeBuild', + input: sourceOutput, + project: codeBuildProject, + executeBatchBuild: true, + }), + ], + }, + ], + }); + + expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', { + 'Stages': [ + { + 'Name': 'Source', + }, + { + 'Name': 'Build', + 'Actions': [ + { + 'Name': 'CodeBuild', + 'Configuration': { + 'BatchEnabled': 'true', + }, + }, + ], + }, + ], + })); + + test.done(); + }, }, };