Skip to content

Commit

Permalink
feat(aws-codepipeline): New Pipeline#addStage convenience method. (#647)
Browse files Browse the repository at this point in the history
Added to make creating Stage objects a little more concise.
  • Loading branch information
skinny85 committed Sep 17, 2018
1 parent 965b918 commit 25c9fa0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/@aws-cdk/aws-codepipeline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
Expand Down
24 changes: 24 additions & 0 deletions packages/@aws-cdk/aws-codepipeline/test/test.stages.ts
Original file line number Diff line number Diff line change
@@ -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();
},
},
};

0 comments on commit 25c9fa0

Please sign in to comment.