Skip to content

Commit

Permalink
feat(aws-codebuild): New method addBuildToPipeline on Project.
Browse files Browse the repository at this point in the history
See #265 for the discussion about this feature.
  • Loading branch information
skinny85 committed Aug 31, 2018
1 parent c8b7a49 commit 783dcb3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
9 changes: 9 additions & 0 deletions packages/@aws-cdk/aws-codebuild/README.md
Expand Up @@ -80,6 +80,15 @@ const project = new codebuild.Project(this, 'MyProject', {
}
```
You can also add the Project to the Pipeline directly:
```ts
// equivalent to the code above:
project.addBuildToPipeline(buildStage, 'CodeBuild', {
inputArtifact: sourceAction.artifact,
})
```
### Using Project as an event target
The `Project` construct implements the `IEventRuleTarget` interface. This means that it can be
Expand Down
11 changes: 9 additions & 2 deletions packages/@aws-cdk/aws-codebuild/lib/pipeline-actions.ts
Expand Up @@ -3,9 +3,11 @@ import cdk = require('@aws-cdk/cdk');
import { ProjectRef } from './project';

/**
* Construction properties of the {@link PipelineBuildAction CodeBuild build CodePipeline Action}.
* Common properties for creating {@link PipelineBuildAction} -
* either directly, through its constructor,
* or through {@link ProjectRef#addBuildToPipeline}.
*/
export interface PipelineBuildActionProps extends codepipeline.CommonActionProps {
export interface CommonPipelineBuildActionProps {
/**
* The source to use as input for this build
*/
Expand All @@ -15,7 +17,12 @@ export interface PipelineBuildActionProps extends codepipeline.CommonActionProps
* The name of the build's output artifact
*/
artifactName?: string;
}

/**
* Construction properties of the {@link PipelineBuildAction CodeBuild build CodePipeline Action}.
*/
export interface PipelineBuildActionProps extends CommonPipelineBuildActionProps, codepipeline.CommonActionProps {
/**
* The build project
*/
Expand Down
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
@@ -1,11 +1,13 @@
import cloudwatch = require('@aws-cdk/aws-cloudwatch');
import codepipeline = require('@aws-cdk/aws-codepipeline-api');
import events = require('@aws-cdk/aws-events');
import iam = require('@aws-cdk/aws-iam');
import kms = require('@aws-cdk/aws-kms');
import s3 = require('@aws-cdk/aws-s3');
import cdk = require('@aws-cdk/cdk');
import { BuildArtifacts, CodePipelineBuildArtifacts, NoBuildArtifacts } from './artifacts';
import { cloudformation, ProjectArn, ProjectName } from './codebuild.generated';
import { CommonPipelineBuildActionProps, PipelineBuildAction } from './pipeline-actions';
import { BuildSource } from './source';

const CODEPIPELINE_TYPE = 'CODEPIPELINE';
Expand Down Expand Up @@ -75,6 +77,23 @@ export abstract class ProjectRef extends cdk.Construct implements events.IEventR
};
}

/**
* Convenience method for creating a new {@link PipelineBuildAction} build Action,
* and adding it to the given Stage.
*
* @param stage the Pipeline Stage to add the new Action to
* @param name the name of the newly created Action
* @param props the properties of the new Action
* @returns the newly created {@link PipelineSource} Action
*/
public addBuildToPipeline(stage: codepipeline.IStage, name: string, props: CommonPipelineBuildActionProps): PipelineBuildAction {
return new PipelineBuildAction(this.parent!, name, {
stage,
project: this,
...props,
});
}

/**
* Defines a CloudWatch event rule triggered when the build project state
* changes. You can filter specific build status events using an event
Expand Down
Expand Up @@ -25,10 +25,8 @@ const project = new codebuild.Project(stack, 'MyBuildProject', {
});

const buildStage = new codepipeline.Stage(pipeline, 'build', { pipeline });
new codebuild.PipelineBuildAction(buildStage, 'build', {
stage: buildStage,
project.addBuildToPipeline(buildStage, 'build', {
inputArtifact: source.artifact,
project,
});

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

0 comments on commit 783dcb3

Please sign in to comment.