Skip to content

Commit

Permalink
feat(codebuild): allow setting concurrent build limit (#14185)
Browse files Browse the repository at this point in the history
Add support for specifying the concurrent build limit for codebuild project.

This is identical to #14099 - which could not be merged because it was based on fork in corporate github organization.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
gmokki committed Apr 15, 2021
1 parent 0a7157d commit 3107d03
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-codebuild/README.md
Expand Up @@ -648,3 +648,17 @@ new codebuild.Project(stack, 'MyProject', {
queuedTimeout: Duration.minutes(30)
});
```

## Limiting concurrency

By default if a new build is triggered it will be run even if there is a previous build already in progress.
It is possible to limit the maximum concurrent builds to value between 1 and the account specific maximum limit.
By default there is no explicit limit.

```ts
import * as codebuild from '@aws-cdk/aws-codebuild';

new codebuild.Project(stack, 'MyProject', {
concurrentBuildLimit: 1
});
```
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Expand Up @@ -584,6 +584,13 @@ export interface CommonProjectProps {
* @default - no queue timeout is set
*/
readonly queuedTimeout?: Duration

/**
* Maximum number of concurrent builds. Minimum value is 1 and maximum is account build limit.
*
* @default - no explicit limit is set
*/
readonly concurrentBuildLimit?: number
}

export interface ProjectProps extends CommonProjectProps {
Expand Down Expand Up @@ -917,6 +924,7 @@ export class Project extends ProjectBase {
name: this.physicalName,
timeoutInMinutes: props.timeout && props.timeout.toMinutes(),
queuedTimeoutInMinutes: props.queuedTimeout && props.queuedTimeout.toMinutes(),
concurrentBuildLimit: props.concurrentBuildLimit,
secondarySources: Lazy.any({ produce: () => this.renderSecondarySources() }),
secondarySourceVersions: Lazy.any({ produce: () => this.renderSecondarySourceVersions() }),
secondaryArtifacts: Lazy.any({ produce: () => this.renderSecondaryArtifacts() }),
Expand Down
23 changes: 23 additions & 0 deletions packages/@aws-cdk/aws-codebuild/test/test.project.ts
Expand Up @@ -1409,6 +1409,29 @@ export = {
},
},

'Maximum concurrency': {
'can limit maximum concurrency'(test: Test) {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new codebuild.Project(stack, 'Project', {
source: codebuild.Source.s3({
bucket: new s3.Bucket(stack, 'Bucket'),
path: 'path',
}),
concurrentBuildLimit: 1,
});

// THEN
expect(stack).to(haveResourceLike('AWS::CodeBuild::Project', {
ConcurrentBuildLimit: 1,
}));

test.done();
},
},

'can be imported': {
'by ARN'(test: Test) {
const stack = new cdk.Stack();
Expand Down

0 comments on commit 3107d03

Please sign in to comment.