Skip to content
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

feat(codebuild): add startBatchBuild option #11743

Merged
merged 14 commits into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-codebuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const gitHubSource = codebuild.Source.gitHub({
owner: 'awslabs',
repo: 'aws-cdk',
webhook: true, // optional, default: true if `webhookFilters` were provided, false otherwise
startBatchBuild: true, // optional, default is false
webhookFilters: [
codebuild.FilterGroup
.inEventOf(codebuild.EventAction.PUSH)
Expand Down
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-codebuild/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,13 @@ interface ThirdPartyGitSourceProps extends GitSourceProps {
*/
readonly webhook?: boolean;

/**
* Start a batch build instead of a standard one.
*
* @default false
*/
readonly startBatchBuild?: boolean;

/**
* A list of webhook filters that can constraint what events in the repository will trigger a build.
* A build is triggered if any of the provided filter groups match.
Expand All @@ -500,13 +507,15 @@ abstract class ThirdPartyGitSource extends GitSource {
protected readonly webhookFilters: FilterGroup[];
private readonly reportBuildStatus: boolean;
private readonly webhook?: boolean;
private readonly startBatchBuild?: boolean;

protected constructor(props: ThirdPartyGitSourceProps) {
super(props);

this.webhook = props.webhook;
this.reportBuildStatus = props.reportBuildStatus === undefined ? true : props.reportBuildStatus;
this.webhookFilters = props.webhookFilters || [];
this.startBatchBuild = props.startBatchBuild;
}

public bind(_scope: CoreConstruct, _project: IProject): SourceConfig {
Expand All @@ -522,6 +531,7 @@ abstract class ThirdPartyGitSource extends GitSource {
sourceVersion: superConfig.sourceVersion,
buildTriggers: webhook === undefined ? undefined : {
webhook,
buildType: this.startBatchBuild ? 'BUILD_BATCH' : undefined,
filterGroups: anyFilterGroupsProvided ? this.webhookFilters.map(fg => fg._toJson()) : undefined,
},
};
Expand Down
40 changes: 40 additions & 0 deletions packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,46 @@ export = {

test.done();
},

'with startBatchBuild option'(test: Test) {
tjenkinson marked this conversation as resolved.
Show resolved Hide resolved
const stack = new cdk.Stack();

new codebuild.Project(stack, 'Project', {
source: codebuild.Source.gitHub({
owner: 'testowner',
repo: 'testrepo',
cloneDepth: 3,
fetchSubmodules: true,
webhook: true,
startBatchBuild: true,
reportBuildStatus: false,
webhookFilters: [
codebuild.FilterGroup.inEventOf(codebuild.EventAction.PUSH).andTagIsNot('stable'),
codebuild.FilterGroup.inEventOf(codebuild.EventAction.PULL_REQUEST_REOPENED).andBaseBranchIs('master'),
],
}),
});

expect(stack).to(haveResourceLike('AWS::CodeBuild::Project', {
Triggers: {
Webhook: true,
BuildType: 'BUILD_BATCH',
FilterGroups: [
[
{ Type: 'EVENT', Pattern: 'PUSH' },
{ Type: 'HEAD_REF', Pattern: 'refs/tags/stable', ExcludeMatchedPattern: true },
],
[
{ Type: 'EVENT', Pattern: 'PULL_REQUEST_REOPENED' },
{ Type: 'BASE_REF', Pattern: 'refs/heads/master' },
],
],
},
}));

test.done();
},
tjenkinson marked this conversation as resolved.
Show resolved Hide resolved

'fail creating a Project when no build spec is given'(test: Test) {
const stack = new cdk.Stack();

Expand Down