Skip to content

Commit

Permalink
feat(codepipeline-actions): support executeBatchBuild on `CodeBuild…
Browse files Browse the repository at this point in the history
…Action` (#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
  • Loading branch information
tjenkinson authored Dec 3, 2020
1 parent cacb1d7 commit 3dcd1a8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-codepipeline-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
},
};

0 comments on commit 3dcd1a8

Please sign in to comment.