@@ -30,7 +30,7 @@ $ npm i @aws-cdk/aws-codebuild
30
30
31
31
Import it into your code:
32
32
33
- ``` ts
33
+ ``` ts nofixture
34
34
import * as codebuild from ' @aws-cdk/aws-codebuild' ;
35
35
```
36
36
@@ -56,7 +56,6 @@ CodeBuild!`:
56
56
Use an AWS CodeCommit repository as the source of this build:
57
57
58
58
``` ts
59
- import * as codebuild from ' @aws-cdk/aws-codebuild' ;
60
59
import * as codecommit from ' @aws-cdk/aws-codecommit' ;
61
60
62
61
const repository = new codecommit .Repository (this , ' MyRepo' , { repositoryName: ' foo' });
@@ -70,10 +69,8 @@ new codebuild.Project(this, 'MyFirstCodeCommitProject', {
70
69
Create a CodeBuild project with an S3 bucket as the source:
71
70
72
71
``` ts
73
- import * as codebuild from ' @aws-cdk/aws-codebuild' ;
74
- import * as s3 from ' @aws-cdk/aws-s3' ;
75
-
76
72
const bucket = new s3 .Bucket (this , ' MyBucket' );
73
+
77
74
new codebuild .Project (this , ' MyProject' , {
78
75
source: codebuild .Source .s3 ({
79
76
bucket: bucket ,
@@ -140,7 +137,9 @@ const gitHubSource = codebuild.Source.gitHub({
140
137
CodeBuild Projects can produce Artifacts and upload them to S3. For example:
141
138
142
139
``` ts
143
- const project = codebuild .Project (stack , ' MyProject' , {
140
+ declare const bucket: s3 .Bucket ;
141
+
142
+ const project = new codebuild .Project (this , ' MyProject' , {
144
143
buildSpec: codebuild .BuildSpec .fromObject ({
145
144
version: ' 0.2' ,
146
145
}),
@@ -193,7 +192,7 @@ new codebuild.Project(this, 'Project', {
193
192
owner: ' awslabs' ,
194
193
repo: ' aws-cdk' ,
195
194
}),
196
- cache: codebuild .Cache .bucket (new Bucket (this , ' Bucket' ))
195
+ cache: codebuild .Cache .bucket (new s3 . Bucket (this , ' Bucket' ))
197
196
});
198
197
```
199
198
@@ -214,7 +213,7 @@ new codebuild.Project(this, 'Project', {
214
213
}),
215
214
216
215
// Enable Docker AND custom caching
217
- cache: codebuild .Cache .local (LocalCacheMode .DOCKER_LAYER , LocalCacheMode .CUSTOM )
216
+ cache: codebuild .Cache .local (codebuild . LocalCacheMode .DOCKER_LAYER , codebuild . LocalCacheMode .CUSTOM )
218
217
});
219
218
```
220
219
@@ -260,6 +259,8 @@ Note that the `WindowsBuildImage` version of the static methods accepts an optio
260
259
which can be either ` WindowsImageType.STANDARD ` , the default, or ` WindowsImageType.SERVER_2019 ` :
261
260
262
261
``` ts
262
+ declare const ecrRepository: ecr .Repository ;
263
+
263
264
new codebuild .Project (this , ' Project' , {
264
265
environment: {
265
266
buildImage: codebuild .WindowsBuildImage .fromEcrRepository (ecrRepository , ' v1.0' , codebuild .WindowsImageType .SERVER_2019 ),
@@ -269,7 +270,7 @@ new codebuild.Project(this, 'Project', {
269
270
objectKey: ' path/to/cert.pem' ,
270
271
},
271
272
},
272
- ...
273
+ // ...
273
274
})
274
275
```
275
276
@@ -296,7 +297,7 @@ new codebuild.Project(this, 'Project', {
296
297
environment: {
297
298
buildImage: codebuild .LinuxGpuBuildImage .DLC_TENSORFLOW_2_1_0_INFERENCE ,
298
299
},
299
- ...
300
+ // ...
300
301
})
301
302
```
302
303
@@ -315,7 +316,7 @@ new codebuild.Project(this, 'Project', {
315
316
buildImage: codebuild .LinuxGpuBuildImage .awsDeepLearningContainersImage (
316
317
' tensorflow-inference' , ' 2.1.0-gpu-py36-cu101-ubuntu18.04' , ' 123456789012' ),
317
318
},
318
- ...
319
+ // ...
319
320
})
320
321
```
321
322
@@ -331,10 +332,9 @@ By default, logs will go to cloudwatch.
331
332
new codebuild .Project (this , ' Project' , {
332
333
logging: {
333
334
cloudWatch: {
334
- logGroup: new cloudwatch .LogGroup (this , ` MyLogGroup ` ),
335
+ logGroup: new logs .LogGroup (this , ` MyLogGroup ` ),
335
336
}
336
337
},
337
- ...
338
338
})
339
339
```
340
340
@@ -347,7 +347,6 @@ new codebuild.Project(this, 'Project', {
347
347
bucket: new s3 .Bucket (this , ` LogBucket ` )
348
348
}
349
349
},
350
- ...
351
350
})
352
351
```
353
352
@@ -358,7 +357,7 @@ like GitHub:
358
357
359
358
``` ts
360
359
new codebuild .GitHubSourceCredentials (this , ' CodeBuildGitHubCreds' , {
361
- accessToken: cdk . SecretValue .secretsManager (' my-token' ),
360
+ accessToken: SecretValue .secretsManager (' my-token' ),
362
361
});
363
362
// GitHub Enterprise is almost the same,
364
363
// except the class is called GitHubEnterpriseSourceCredentials
@@ -368,8 +367,8 @@ and BitBucket:
368
367
369
368
``` ts
370
369
new codebuild .BitBucketSourceCredentials (this , ' CodeBuildBitBucketCreds' , {
371
- username: cdk . SecretValue .secretsManager (' my-bitbucket-creds' , { jsonField: ' username' }),
372
- password: cdk . SecretValue .secretsManager (' my-bitbucket-creds' , { jsonField: ' password' }),
370
+ username: SecretValue .secretsManager (' my-bitbucket-creds' , { jsonField: ' username' }),
371
+ password: SecretValue .secretsManager (' my-bitbucket-creds' , { jsonField: ' password' }),
373
372
});
374
373
```
375
374
@@ -409,8 +408,10 @@ if you'd rather not have those permissions added,
409
408
you can opt out of it when creating the project:
410
409
411
410
``` ts
411
+ declare const source: codebuild .Source ;
412
+
412
413
const project = new codebuild .Project (this , ' Project' , {
413
- // ...
414
+ source ,
414
415
grantReportGroupPermissions: false ,
415
416
});
416
417
```
@@ -419,10 +420,13 @@ Alternatively, you can specify an ARN of an existing resource group,
419
420
instead of a simple name, in your buildspec:
420
421
421
422
``` ts
423
+ declare const source: codebuild .Source ;
424
+
422
425
// create a new ReportGroup
423
426
const reportGroup = new codebuild .ReportGroup (this , ' ReportGroup' );
424
427
425
428
const project = new codebuild .Project (this , ' Project' , {
429
+ source ,
426
430
buildSpec: codebuild .BuildSpec .fromObject ({
427
431
// ...
428
432
reports: {
@@ -438,6 +442,9 @@ const project = new codebuild.Project(this, 'Project', {
438
442
If you do that, you need to grant the project's role permissions to write reports to that report group:
439
443
440
444
``` ts
445
+ declare const project: codebuild .Project ;
446
+ declare const reportGroup: codebuild .ReportGroup ;
447
+
441
448
reportGroup .grantWrite (project );
442
449
```
443
450
@@ -456,8 +463,12 @@ project as a AWS CloudWatch event rule target:
456
463
457
464
``` ts
458
465
// start build when a commit is pushed
466
+ import * as codecommit from ' @aws-cdk/aws-codecommit' ;
459
467
import * as targets from ' @aws-cdk/aws-events-targets' ;
460
468
469
+ declare const codeCommitRepository: codecommit .Repository ;
470
+ declare const project: codebuild .Project ;
471
+
461
472
codeCommitRepository .onCommit (' OnCommit' , {
462
473
target: new targets .CodeBuildProject (project ),
463
474
});
@@ -469,6 +480,10 @@ To define Amazon CloudWatch event rules for build projects, use one of the `onXx
469
480
methods:
470
481
471
482
``` ts
483
+ import * as targets from ' @aws-cdk/aws-events-targets' ;
484
+ declare const fn: lambda .Function ;
485
+ declare const project: codebuild .Project ;
486
+
472
487
const rule = project .onStateChange (' BuildStateChange' , {
473
488
target: new targets .LambdaFunction (fn )
474
489
});
@@ -480,7 +495,11 @@ To define CodeStar Notification rules for Projects, use one of the `notifyOnXxx(
480
495
They are very similar to ` onXxx() ` methods for CloudWatch events:
481
496
482
497
``` ts
483
- const target = new chatbot .SlackChannelConfiguration (stack , ' MySlackChannel' , {
498
+ import * as chatbot from ' @aws-cdk/aws-chatbot' ;
499
+
500
+ declare const project: codebuild .Project ;
501
+
502
+ const target = new chatbot .SlackChannelConfiguration (this , ' MySlackChannel' , {
484
503
slackChannelConfigurationName: ' YOUR_CHANNEL_NAME' ,
485
504
slackWorkspaceId: ' YOUR_SLACK_WORKSPACE_ID' ,
486
505
slackChannelId: ' YOUR_SLACK_CHANNEL_ID' ,
@@ -495,6 +514,10 @@ CodeBuild Projects can get their sources from multiple places, and produce
495
514
multiple outputs. For example:
496
515
497
516
``` ts
517
+ import * as codecommit from ' @aws-cdk/aws-codecommit' ;
518
+ declare const repo: codecommit .Repository ;
519
+ declare const bucket: s3 .Bucket ;
520
+
498
521
const project = new codebuild .Project (this , ' MyProject' , {
499
522
secondarySources: [
500
523
codebuild .Source .codeCommit ({
@@ -586,6 +609,8 @@ to access the resources that it needs by using the
586
609
For example:
587
610
588
611
``` ts
612
+ declare const loadBalancer: elbv2 .ApplicationLoadBalancer ;
613
+
589
614
const vpc = new ec2 .Vpc (this , ' MyVPC' );
590
615
const project = new codebuild .Project (this , ' MyProject' , {
591
616
vpc: vpc ,
@@ -608,7 +633,7 @@ The only supported file system type is `EFS`.
608
633
For example:
609
634
610
635
``` ts
611
- new codebuild .Project (stack , ' MyProject' , {
636
+ new codebuild .Project (this , ' MyProject' , {
612
637
buildSpec: codebuild .BuildSpec .fromObject ({
613
638
version: ' 0.2' ,
614
639
}),
@@ -635,9 +660,9 @@ It returns an object containing the batch service role that was created,
635
660
or ` undefined ` if batch builds could not be enabled, for example if the project was imported.
636
661
637
662
``` ts
638
- import * as codebuild from ' @aws-cdk/aws-codebuild ' ;
663
+ declare const source : codebuild . Source ;
639
664
640
- const project = new codebuild .Project (this , ' MyProject' , { ... });
665
+ const project = new codebuild .Project (this , ' MyProject' , { source , });
641
666
642
667
if (project .enableBatchBuilds ()) {
643
668
console .log (' Batch builds were enabled' );
@@ -652,9 +677,7 @@ The default is 60 minutes.
652
677
An example of overriding the default follows.
653
678
654
679
``` ts
655
- import * as codebuild from ' @aws-cdk/aws-codebuild' ;
656
-
657
- new codebuild .Project (stack , ' MyProject' , {
680
+ new codebuild .Project (this , ' MyProject' , {
658
681
timeout: Duration .minutes (90 )
659
682
});
660
683
```
@@ -665,9 +688,7 @@ As an example, to allow your Project to queue for up to thirty (30) minutes befo
665
688
use the following code.
666
689
667
690
``` ts
668
- import * as codebuild from ' @aws-cdk/aws-codebuild' ;
669
-
670
- new codebuild .Project (stack , ' MyProject' , {
691
+ new codebuild .Project (this , ' MyProject' , {
671
692
queuedTimeout: Duration .minutes (30 )
672
693
});
673
694
```
@@ -679,9 +700,7 @@ It is possible to limit the maximum concurrent builds to value between 1 and the
679
700
By default there is no explicit limit.
680
701
681
702
``` ts
682
- import * as codebuild from ' @aws-cdk/aws-codebuild' ;
683
-
684
- new codebuild .Project (stack , ' MyProject' , {
703
+ new codebuild .Project (this , ' MyProject' , {
685
704
concurrentBuildLimit: 1
686
705
});
687
706
```
0 commit comments