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..cfdbbeccb1b13 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, name, { + pipeline: this, + }); + } + /** * Adds a statement to the pipeline role. */ diff --git a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit.ts b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit.ts index 803f323e23411..83688e91aa687 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit.ts +++ b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit.ts @@ -10,7 +10,7 @@ const repo = new codecommit.Repository(stack, 'MyRepo', { repositoryName: 'my-re const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); -const sourceStage = new codepipeline.Stage(pipeline, 'source', { pipeline }); +const sourceStage = pipeline.addStage('source'); repo.addToPipeline(sourceStage, 'source', { artifactName: 'SourceArtifact', });