diff --git a/packages/@aws-cdk/aws-codedeploy/README.md b/packages/@aws-cdk/aws-codedeploy/README.md index 4b79deb7b9343..415024f7e7bc6 100644 --- a/packages/@aws-cdk/aws-codedeploy/README.md +++ b/packages/@aws-cdk/aws-codedeploy/README.md @@ -174,7 +174,13 @@ const pipeline = new codepipeline.Pipeline(this, 'MyPipeline', { const deployStage = pipeline.addStage('Deploy'); new codedeploy.PipelineDeployAction(this, 'CodeDeploy', { stage: deployStage, - applicationName: 'YourCodeDeployApplicationName', - deploymentGroupName: 'YourCodeDeployDeploymentGroupName', + deploymentGroup, }); ``` + +You can also add the Deployment Group to the Pipeline directly: + +```ts +// equivalent to the code above: +deploymentGroup.addToPipeline(deployStage, 'CodeDeploy'); +``` diff --git a/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts index 5857d64be0a86..88b6e6a1be962 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts @@ -1,6 +1,7 @@ import autoscaling = require("@aws-cdk/aws-autoscaling"); import cloudwatch = require("@aws-cdk/aws-cloudwatch"); import codedeploylb = require("@aws-cdk/aws-codedeploy-api"); +import codepipeline = require("@aws-cdk/aws-codepipeline-api"); import ec2 = require("@aws-cdk/aws-ec2"); import iam = require('@aws-cdk/aws-iam'); import s3 = require("@aws-cdk/aws-s3"); @@ -8,6 +9,7 @@ import cdk = require("@aws-cdk/cdk"); import { ServerApplication, ServerApplicationRef } from "./application"; import { cloudformation } from './codedeploy.generated'; import { IServerDeploymentConfig, ServerDeploymentConfig } from "./deployment-config"; +import { CommonPipelineDeployActionProps, PipelineDeployAction } from "./pipeline-action"; /** * Properties of a reference to a CodeDeploy EC2/on-premise Deployment Group. @@ -81,6 +83,24 @@ export abstract class ServerDeploymentGroupRef extends cdk.Construct { deploymentConfig: this.deploymentConfig, }; } + + /** + * Convenience method for creating a new {@link PipelineDeployAction} + * 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 PipelineDeployAction} deploy Action + */ + public addToPipeline(stage: codepipeline.IStage, name: string, props: CommonPipelineDeployActionProps = {}): + PipelineDeployAction { + return new PipelineDeployAction(this, name, { + deploymentGroup: this, + stage, + ...props, + }); + } } class ImportedServerDeploymentGroupRef extends ServerDeploymentGroupRef { diff --git a/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts b/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts index 0d1a9635f80ba..58985c522273d 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts @@ -4,15 +4,11 @@ import cdk = require('@aws-cdk/cdk'); import { ServerDeploymentGroupRef } from './deployment-group'; /** - * Construction properties of the {@link PipelineDeployAction CodeDeploy deploy CodePipeline Action}. + * Common properties for creating a {@link PipelineDeployAction}, + * either directly, through its constructor, + * or through {@link ServerDeploymentGroupRef#addToPipeline}. */ -export interface PipelineDeployActionProps extends codepipeline.CommonActionProps, - codepipeline.CommonActionConstructProps { - /** - * The CodeDeploy Deployment Group to deploy to. - */ - deploymentGroup: ServerDeploymentGroupRef; - +export interface CommonPipelineDeployActionProps extends codepipeline.CommonActionProps { /** * The source to use as input for deployment. * @@ -21,6 +17,17 @@ export interface PipelineDeployActionProps extends codepipeline.CommonActionProp inputArtifact?: codepipeline.Artifact; } +/** + * Construction properties of the {@link PipelineDeployAction CodeDeploy deploy CodePipeline Action}. + */ +export interface PipelineDeployActionProps extends CommonPipelineDeployActionProps, + codepipeline.CommonActionConstructProps { + /** + * The CodeDeploy Deployment Group to deploy to. + */ + deploymentGroup: ServerDeploymentGroupRef; +} + export class PipelineDeployAction extends codepipeline.DeployAction { constructor(parent: cdk.Construct, id: string, props: PipelineDeployActionProps) { super(parent, id, { diff --git a/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts b/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts index 67df1ecfdcbce..b44485f8843c1 100644 --- a/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts +++ b/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts @@ -88,7 +88,8 @@ export interface IPipeline extends events.IEventRuleTarget { */ readonly role: iam.Role; - /* Grants read permissions to the Pipeline's S3 Bucket to the given Identity. + /** + * Grants read permissions to the Pipeline's S3 Bucket to the given Identity. * * @param identity the IAM Identity to grant the permissions to */ diff --git a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-deploy.ts b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-deploy.ts index b6f71cf5e3679..f52c9dc36b61b 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-deploy.ts +++ b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-deploy.ts @@ -36,9 +36,6 @@ bucket.addToPipeline(sourceStage, 'S3Source', { }); const deployStage = new codepipeline.Stage(stack, 'Deploy', { pipeline }); -new codedeploy.PipelineDeployAction(stack, 'CodeDeploy', { - stage: deployStage, - deploymentGroup, -}); +deploymentGroup.addToPipeline(deployStage, 'CodeDeploy'); app.run();