Skip to content

Commit 25c9fa0

Browse files
authored
feat(aws-codepipeline): New Pipeline#addStage convenience method. (#647)
Added to make creating Stage objects a little more concise.
1 parent 965b918 commit 25c9fa0

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ const pipeline = new Pipeline(this, 'MyFirstPipeline', {
1111
Append a Stage to the Pipeline:
1212

1313
```ts
14-
const sourceStage = new Stage(this, 'Source', {
15-
pipeline,
16-
});
14+
const sourceStage = pipeline.addStage('Source');
1715
```
1816

17+
You can also instantiate the `Stage` Construct directly,
18+
which will add it to the Pipeline provided in its construction properties.
19+
1920
Add an Action to a Stage:
2021

2122
```ts

packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ export class Pipeline extends cdk.Construct implements events.IEventRuleTarget {
121121
}));
122122
}
123123

124+
/**
125+
* Convenience method for creating a new {@link Stage},
126+
* and adding it to this Pipeline.
127+
*
128+
* @param name the name of the newly created Stage
129+
* @returns the newly created Stage
130+
*/
131+
public addStage(name: string): Stage {
132+
return new Stage(this, name, {
133+
pipeline: this,
134+
});
135+
}
136+
124137
/**
125138
* Adds a statement to the pipeline role.
126139
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const repo = new codecommit.Repository(stack, 'MyRepo', { repositoryName: 'my-re
1010

1111
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline');
1212

13-
const sourceStage = new codepipeline.Stage(pipeline, 'source', { pipeline });
13+
const sourceStage = pipeline.addStage('source');
1414
repo.addToPipeline(sourceStage, 'source', {
1515
artifactName: 'SourceArtifact',
1616
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect, haveResource } from '@aws-cdk/assert';
2+
import cdk = require('@aws-cdk/cdk');
3+
import { Test } from 'nodeunit';
4+
import codepipeline = require('../lib');
5+
6+
// tslint:disable:object-literal-key-quotes
7+
8+
export = {
9+
'Pipeline Stages': {
10+
'can also be created by using the Pipeline#addStage method'(test: Test) {
11+
const stack = new cdk.Stack();
12+
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline');
13+
pipeline.addStage('Stage');
14+
15+
expect(stack, true).to(haveResource('AWS::CodePipeline::Pipeline', {
16+
"Stages": [
17+
{ "Name": "Stage" },
18+
],
19+
}));
20+
21+
test.done();
22+
},
23+
},
24+
};

0 commit comments

Comments
 (0)