diff --git a/packages/@aws-cdk/aws-codepipeline/README.md b/packages/@aws-cdk/aws-codepipeline/README.md index 9cbb2d48b3dad..b92ea8ad1f870 100644 --- a/packages/@aws-cdk/aws-codepipeline/README.md +++ b/packages/@aws-cdk/aws-codepipeline/README.md @@ -16,6 +16,13 @@ const sourceStage = new Stage(this, 'Source', { }); ``` +There's also a utility method on the `Pipeline` class that can be used for this purpose: + +```ts +// equivalent to the code above: +const sourceStage = pipeline.addStage('Source'); +``` + Add an Action to a Stage: ```ts diff --git a/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts b/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts index ffe8b6f01c214..f4dc9bc269152 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts @@ -121,6 +121,19 @@ export class Pipeline extends cdk.Construct implements events.IEventRuleTarget { })); } + /** + * Convenience method for creating a new {@link Stage}, + * and adding it to this Pipeline. + * + * @param name the name of the newly created Stage + * @returns the newly created Stage + */ + public addStage(name: string): Stage { + return new Stage(this.parent!, name, { + pipeline: this, + }); + } + /** * Adds a statement to the pipeline role. */ 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 3df11ab1beb14..e291baffe3f35 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 @@ -24,13 +24,13 @@ const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', { artifactBucket: bucket, }); -const sourceStage = new codepipeline.Stage(stack, 'Source', { pipeline }); +const sourceStage = pipeline.addStage('Source'); const sourceAction = bucket.addToPipeline(sourceStage, 'S3Source', { bucketKey: 'application.zip', artifactName: 'SourceOutput', }); -const deployStage = new codepipeline.Stage(stack, 'Deploy', { pipeline }); +const deployStage = pipeline.addStage('Deploy'); new codedeploy.PipelineDeployAction(stack, 'CodeDeploy', { stage: deployStage, inputArtifact: sourceAction.artifact,