Skip to content

Commit

Permalink
feat(codebuild): allow setting queued timeout (#13467)
Browse files Browse the repository at this point in the history
Closes #11364

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
ialford committed Mar 8, 2021
1 parent e567a41 commit e09250b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/@aws-cdk/aws-codebuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,31 @@ if (project.enableBatchBuilds()) {
console.log('Batch builds were enabled');
}
```

## Timeouts

There are two types of timeouts that can be set when creating your Project.
The `timeout` property can be used to set an upper limit on how long your Project is able to run without being marked as completed.
The default is 60 minutes.
An example of overriding the default follows.

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

new codebuild.Project(stack, 'MyProject', {
timeout: Duration.minutes(90)
});
```

The `queuedTimeout` property can be used to set an upper limit on how your Project remains queued to run.
There is no default value for this property.
As an example, to allow your Project to queue for up to thirty (30) minutes before the build fails,
use the following code.

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

new codebuild.Project(stack, 'MyProject', {
queuedTimeout: Duration.minutes(30)
});
```
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,15 @@ export interface CommonProjectProps {
* @default - no log configuration is set
*/
readonly logging?: LoggingOptions;

/**
* The number of minutes after which AWS CodeBuild stops the build if it's
* still in queue. For valid values, see the timeoutInMinutes field in the AWS
* CodeBuild User Guide.
*
* @default - no queue timeout is set
*/
readonly queuedTimeout?: Duration
}

export interface ProjectProps extends CommonProjectProps {
Expand Down Expand Up @@ -869,6 +878,7 @@ export class Project extends ProjectBase {
cache: cache._toCloudFormation(),
name: this.physicalName,
timeoutInMinutes: props.timeout && props.timeout.toMinutes(),
queuedTimeoutInMinutes: props.queuedTimeout && props.queuedTimeout.toMinutes(),
secondarySources: Lazy.any({ produce: () => this.renderSecondarySources() }),
secondarySourceVersions: Lazy.any({ produce: () => this.renderSecondarySourceVersions() }),
secondaryArtifacts: Lazy.any({ produce: () => this.renderSecondaryArtifacts() }),
Expand Down
43 changes: 43 additions & 0 deletions packages/@aws-cdk/aws-codebuild/test/test.project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,4 +960,47 @@ export = {
test.done();
},
},

'Timeouts': {
'can add queued timeout'(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',
}),
queuedTimeout: cdk.Duration.minutes(30),
});

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

test.done();
},
'can override build timeout'(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',
}),
timeout: cdk.Duration.minutes(30),
});

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

test.done();
},
},
};

0 comments on commit e09250b

Please sign in to comment.