Skip to content

Commit bdbeb7c

Browse files
skinny85Elad Ben-Israel
authored andcommitted
feat(aws-codedeploy): add an addToPipeline method to Deployment Group. (#1166)
1 parent 179b269 commit bdbeb7c

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,13 @@ const pipeline = new codepipeline.Pipeline(this, 'MyPipeline', {
174174
const deployStage = pipeline.addStage('Deploy');
175175
new codedeploy.PipelineDeployAction(this, 'CodeDeploy', {
176176
stage: deployStage,
177-
applicationName: 'YourCodeDeployApplicationName',
178-
deploymentGroupName: 'YourCodeDeployDeploymentGroupName',
177+
deploymentGroup,
179178
});
180179
```
180+
181+
You can also add the Deployment Group to the Pipeline directly:
182+
183+
```ts
184+
// equivalent to the code above:
185+
deploymentGroup.addToPipeline(deployStage, 'CodeDeploy');
186+
```

packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import autoscaling = require("@aws-cdk/aws-autoscaling");
22
import cloudwatch = require("@aws-cdk/aws-cloudwatch");
33
import codedeploylb = require("@aws-cdk/aws-codedeploy-api");
4+
import codepipeline = require("@aws-cdk/aws-codepipeline-api");
45
import ec2 = require("@aws-cdk/aws-ec2");
56
import iam = require('@aws-cdk/aws-iam');
67
import s3 = require("@aws-cdk/aws-s3");
78
import cdk = require("@aws-cdk/cdk");
89
import { ServerApplication, ServerApplicationRef } from "./application";
910
import { cloudformation } from './codedeploy.generated';
1011
import { IServerDeploymentConfig, ServerDeploymentConfig } from "./deployment-config";
12+
import { CommonPipelineDeployActionProps, PipelineDeployAction } from "./pipeline-action";
1113

1214
/**
1315
* Properties of a reference to a CodeDeploy EC2/on-premise Deployment Group.
@@ -81,6 +83,24 @@ export abstract class ServerDeploymentGroupRef extends cdk.Construct {
8183
deploymentConfig: this.deploymentConfig,
8284
};
8385
}
86+
87+
/**
88+
* Convenience method for creating a new {@link PipelineDeployAction}
89+
* and adding it to the given Stage.
90+
*
91+
* @param stage the Pipeline Stage to add the new Action to
92+
* @param name the name of the newly created Action
93+
* @param props the properties of the new Action
94+
* @returns the newly created {@link PipelineDeployAction} deploy Action
95+
*/
96+
public addToPipeline(stage: codepipeline.IStage, name: string, props: CommonPipelineDeployActionProps = {}):
97+
PipelineDeployAction {
98+
return new PipelineDeployAction(this, name, {
99+
deploymentGroup: this,
100+
stage,
101+
...props,
102+
});
103+
}
84104
}
85105

86106
class ImportedServerDeploymentGroupRef extends ServerDeploymentGroupRef {

packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ import cdk = require('@aws-cdk/cdk');
44
import { ServerDeploymentGroupRef } from './deployment-group';
55

66
/**
7-
* Construction properties of the {@link PipelineDeployAction CodeDeploy deploy CodePipeline Action}.
7+
* Common properties for creating a {@link PipelineDeployAction},
8+
* either directly, through its constructor,
9+
* or through {@link ServerDeploymentGroupRef#addToPipeline}.
810
*/
9-
export interface PipelineDeployActionProps extends codepipeline.CommonActionProps,
10-
codepipeline.CommonActionConstructProps {
11-
/**
12-
* The CodeDeploy Deployment Group to deploy to.
13-
*/
14-
deploymentGroup: ServerDeploymentGroupRef;
15-
11+
export interface CommonPipelineDeployActionProps extends codepipeline.CommonActionProps {
1612
/**
1713
* The source to use as input for deployment.
1814
*
@@ -21,6 +17,17 @@ export interface PipelineDeployActionProps extends codepipeline.CommonActionProp
2117
inputArtifact?: codepipeline.Artifact;
2218
}
2319

20+
/**
21+
* Construction properties of the {@link PipelineDeployAction CodeDeploy deploy CodePipeline Action}.
22+
*/
23+
export interface PipelineDeployActionProps extends CommonPipelineDeployActionProps,
24+
codepipeline.CommonActionConstructProps {
25+
/**
26+
* The CodeDeploy Deployment Group to deploy to.
27+
*/
28+
deploymentGroup: ServerDeploymentGroupRef;
29+
}
30+
2431
export class PipelineDeployAction extends codepipeline.DeployAction {
2532
constructor(parent: cdk.Construct, id: string, props: PipelineDeployActionProps) {
2633
super(parent, id, {

packages/@aws-cdk/aws-codepipeline-api/lib/action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ export interface IPipeline extends events.IEventRuleTarget {
8888
*/
8989
readonly role: iam.Role;
9090

91-
/* Grants read permissions to the Pipeline's S3 Bucket to the given Identity.
91+
/**
92+
* Grants read permissions to the Pipeline's S3 Bucket to the given Identity.
9293
*
9394
* @param identity the IAM Identity to grant the permissions to
9495
*/

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ bucket.addToPipeline(sourceStage, 'S3Source', {
3636
});
3737

3838
const deployStage = new codepipeline.Stage(stack, 'Deploy', { pipeline });
39-
new codedeploy.PipelineDeployAction(stack, 'CodeDeploy', {
40-
stage: deployStage,
41-
deploymentGroup,
42-
});
39+
deploymentGroup.addToPipeline(deployStage, 'CodeDeploy');
4340

4441
app.run();

0 commit comments

Comments
 (0)