diff --git a/packages/@aws-cdk/aws-codepipeline/README.md b/packages/@aws-cdk/aws-codepipeline/README.md index 9cbb2d48b3dad..c47348e969990 100644 --- a/packages/@aws-cdk/aws-codepipeline/README.md +++ b/packages/@aws-cdk/aws-codepipeline/README.md @@ -11,11 +11,12 @@ const pipeline = new Pipeline(this, 'MyFirstPipeline', { Append a Stage to the Pipeline: ```ts -const sourceStage = new Stage(this, 'Source', { - pipeline, -}); +const sourceStage = pipeline.addStage('Source'); ``` +You can also instantiate the `Stage` Construct directly, +which will add it to the Pipeline provided in its construction properties. + 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', }); diff --git a/packages/@aws-cdk/aws-codepipeline/test/test.stages.ts b/packages/@aws-cdk/aws-codepipeline/test/test.stages.ts new file mode 100644 index 0000000000000..754008f63bfa2 --- /dev/null +++ b/packages/@aws-cdk/aws-codepipeline/test/test.stages.ts @@ -0,0 +1,24 @@ +import { expect, haveResource } from '@aws-cdk/assert'; +import cdk = require('@aws-cdk/cdk'); +import { Test } from 'nodeunit'; +import codepipeline = require('../lib'); + +// tslint:disable:object-literal-key-quotes + +export = { + 'Pipeline Stages': { + 'can also be created by using the Pipeline#addStage method'(test: Test) { + const stack = new cdk.Stack(); + const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); + pipeline.addStage('Stage'); + + expect(stack, true).to(haveResource('AWS::CodePipeline::Pipeline', { + "Stages": [ + { "Name": "Stage" }, + ], + })); + + test.done(); + }, + }, +};