Skip to content

Commit 783dcb3

Browse files
committed
feat(aws-codebuild): New method addBuildToPipeline on Project.
See #265 for the discussion about this feature.
1 parent c8b7a49 commit 783dcb3

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

packages/@aws-cdk/aws-codebuild/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ const project = new codebuild.Project(this, 'MyProject', {
8080
}
8181
```
8282
83+
You can also add the Project to the Pipeline directly:
84+
85+
```ts
86+
// equivalent to the code above:
87+
project.addBuildToPipeline(buildStage, 'CodeBuild', {
88+
inputArtifact: sourceAction.artifact,
89+
})
90+
```
91+
8392
### Using Project as an event target
8493
8594
The `Project` construct implements the `IEventRuleTarget` interface. This means that it can be

packages/@aws-cdk/aws-codebuild/lib/pipeline-actions.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import cdk = require('@aws-cdk/cdk');
33
import { ProjectRef } from './project';
44

55
/**
6-
* Construction properties of the {@link PipelineBuildAction CodeBuild build CodePipeline Action}.
6+
* Common properties for creating {@link PipelineBuildAction} -
7+
* either directly, through its constructor,
8+
* or through {@link ProjectRef#addBuildToPipeline}.
79
*/
8-
export interface PipelineBuildActionProps extends codepipeline.CommonActionProps {
10+
export interface CommonPipelineBuildActionProps {
911
/**
1012
* The source to use as input for this build
1113
*/
@@ -15,7 +17,12 @@ export interface PipelineBuildActionProps extends codepipeline.CommonActionProps
1517
* The name of the build's output artifact
1618
*/
1719
artifactName?: string;
20+
}
1821

22+
/**
23+
* Construction properties of the {@link PipelineBuildAction CodeBuild build CodePipeline Action}.
24+
*/
25+
export interface PipelineBuildActionProps extends CommonPipelineBuildActionProps, codepipeline.CommonActionProps {
1926
/**
2027
* The build project
2128
*/

packages/@aws-cdk/aws-codebuild/lib/project.ts

+19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import cloudwatch = require('@aws-cdk/aws-cloudwatch');
2+
import codepipeline = require('@aws-cdk/aws-codepipeline-api');
23
import events = require('@aws-cdk/aws-events');
34
import iam = require('@aws-cdk/aws-iam');
45
import kms = require('@aws-cdk/aws-kms');
56
import s3 = require('@aws-cdk/aws-s3');
67
import cdk = require('@aws-cdk/cdk');
78
import { BuildArtifacts, CodePipelineBuildArtifacts, NoBuildArtifacts } from './artifacts';
89
import { cloudformation, ProjectArn, ProjectName } from './codebuild.generated';
10+
import { CommonPipelineBuildActionProps, PipelineBuildAction } from './pipeline-actions';
911
import { BuildSource } from './source';
1012

1113
const CODEPIPELINE_TYPE = 'CODEPIPELINE';
@@ -75,6 +77,23 @@ export abstract class ProjectRef extends cdk.Construct implements events.IEventR
7577
};
7678
}
7779

80+
/**
81+
* Convenience method for creating a new {@link PipelineBuildAction} build Action,
82+
* and adding it to the given Stage.
83+
*
84+
* @param stage the Pipeline Stage to add the new Action to
85+
* @param name the name of the newly created Action
86+
* @param props the properties of the new Action
87+
* @returns the newly created {@link PipelineSource} Action
88+
*/
89+
public addBuildToPipeline(stage: codepipeline.IStage, name: string, props: CommonPipelineBuildActionProps): PipelineBuildAction {
90+
return new PipelineBuildAction(this.parent!, name, {
91+
stage,
92+
project: this,
93+
...props,
94+
});
95+
}
96+
7897
/**
7998
* Defines a CloudWatch event rule triggered when the build project state
8099
* changes. You can filter specific build status events using an event

packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit-build.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ const project = new codebuild.Project(stack, 'MyBuildProject', {
2525
});
2626

2727
const buildStage = new codepipeline.Stage(pipeline, 'build', { pipeline });
28-
new codebuild.PipelineBuildAction(buildStage, 'build', {
29-
stage: buildStage,
28+
project.addBuildToPipeline(buildStage, 'build', {
3029
inputArtifact: source.artifact,
31-
project,
3230
});
3331

3432
process.stdout.write(app.run());

0 commit comments

Comments
 (0)