Skip to content

Commit

Permalink
fix(codepipeline): correctly validate Artifacts used by Actions in th…
Browse files Browse the repository at this point in the history
…e same Stage.

Fixes aws#2549
  • Loading branch information
skinny85 committed May 16, 2019
1 parent 8e05d49 commit 58b337f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
6 changes: 2 additions & 4 deletions packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ export class Pipeline extends PipelineBase {
for (const stage of this.stages) {
const sortedActions = stage.actions.sort((a1, a2) => a1.runOrder - a2.runOrder);

// start with inputs
for (const action of sortedActions) {
// start with inputs
const inputArtifacts = action.inputs;
for (const inputArtifact of inputArtifacts) {
if (!inputArtifact.artifactName) {
Expand All @@ -508,10 +508,8 @@ export class Pipeline extends PipelineBase {
ret.push(`Artifact '${inputArtifact.artifactName}' was used as input before being used as output`);
}
}
}

// then process outputs by adding them to the Set
for (const action of sortedActions) {
// then process outputs by adding them to the Set
const outputArtifacts = action.outputs;
for (const outputArtifact of outputArtifacts) {
// output Artifacts always have a name set
Expand Down
51 changes: 50 additions & 1 deletion packages/@aws-cdk/aws-codepipeline/test/test.artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import { expect, haveResourceLike } from '@aws-cdk/assert';
import { expect, haveResourceLike } from '@aws-cdk/assert';
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
import codepipeline = require('../lib');
Expand Down Expand Up @@ -123,6 +123,55 @@ export = {

test.done();
},

"an Action's output can be used as input for an Action in the same Stage with a higher runOrder"(test: Test) {
const stack = new cdk.Stack();

const sourceOutput1 = new codepipeline.Artifact('sourceOutput1');
const buildOutput1 = new codepipeline.Artifact('buildOutput1');
const sourceOutput2 = new codepipeline.Artifact('sourceOutput2');

new codepipeline.Pipeline(stack, 'Pipeline', {
stages: [
{
name: 'Source',
actions: [
new FakeSourceAction({
actionName: 'source1',
output: sourceOutput1,
}),
new FakeSourceAction({
actionName: 'source2',
output: sourceOutput2,
}),
],
},
{
name: 'Build',
actions: [
new FakeBuildAction({
actionName: 'build1',
input: sourceOutput1,
output: buildOutput1,
}),
new FakeBuildAction({
actionName: 'build2',
input: sourceOutput2,
extraInputs: [buildOutput1],
output: new codepipeline.Artifact('buildOutput2'),
runOrder: 2,
}),
],
},
],
});

expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', {
//
}));

test.done();
},
},
};

Expand Down

0 comments on commit 58b337f

Please sign in to comment.