Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Pipeline#addStage convenience method #647

Merged
merged 1 commit into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
},
},
};