Skip to content

Commit 5e4a219

Browse files
authoredNov 24, 2021
fix(pipelines): stack outputs used in stackSteps not recognized (#17311)
fixes #17272 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 5710fe5 commit 5e4a219

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
 

‎packages/@aws-cdk/pipelines/lib/helpers-internal/pipeline-queries.ts

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export class PipelineQueries {
1717
steps.push(...wave.pre, ...wave.post);
1818
for (const stage of wave.stages) {
1919
steps.push(...stage.pre, ...stage.post);
20+
for (const stackDeployment of stage.stacks) {
21+
steps.push(...stackDeployment.pre, ...stackDeployment.changeSet, ...stackDeployment.post);
22+
}
2023
}
2124
}
2225

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
import '@aws-cdk/assert-internal/jest';
3+
import * as cdkp from '../../../lib';
4+
import { PipelineQueries } from '../../../lib/helpers-internal/pipeline-queries';
5+
import { AppWithOutput, TestApp } from '../../testhelpers/test-app';
6+
7+
let app: TestApp;
8+
9+
beforeEach(() => {
10+
app = new TestApp();
11+
});
12+
13+
afterEach(() => {
14+
app.cleanup();
15+
});
16+
17+
describe('pipeline-queries', () => {
18+
19+
describe('stackOutputsReferenced', () => {
20+
let blueprint: Blueprint;
21+
let stageDeployment: cdkp.StageDeployment;
22+
let step: cdkp.ShellStep;
23+
let queries: PipelineQueries;
24+
let stackDeployment: cdkp.StackDeployment;
25+
let outputName: string | undefined;
26+
beforeEach(() => {
27+
blueprint = new Blueprint(app, 'Bp', {
28+
synth: new cdkp.ShellStep('Synth', {
29+
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
30+
commands: ['build'],
31+
}),
32+
});
33+
const stage = new AppWithOutput(app, 'CrossAccount');
34+
outputName = 'MyOutput';
35+
stageDeployment = blueprint.addStage(stage);
36+
stackDeployment = stageDeployment.stacks[0];
37+
expect(stackDeployment).not.toBeUndefined();
38+
step = new cdkp.ShellStep('test', {
39+
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
40+
commands: ['build'],
41+
envFromCfnOutputs: {
42+
INPUT: stage.theOutput,
43+
},
44+
});
45+
queries = new PipelineQueries(blueprint);
46+
});
47+
48+
const cases = [
49+
{
50+
description: 'output referenced in stage pre step',
51+
additionalSetup: () => stageDeployment.addPre(step),
52+
expectedResultGetter: () => [outputName],
53+
},
54+
{
55+
description: 'output referenced in stage post step',
56+
additionalSetup: () => stageDeployment.addPost(step),
57+
expectedResultGetter: () => [outputName],
58+
},
59+
{
60+
description: 'output referenced in stack pre step',
61+
additionalSetup: () => stackDeployment.addStackSteps([step], [], []),
62+
expectedResultGetter: () => [outputName],
63+
},
64+
{
65+
description: 'output referenced in stack changeSet step',
66+
additionalSetup: () => stackDeployment.addStackSteps([], [step], []),
67+
expectedResultGetter: () => [outputName],
68+
},
69+
{
70+
description: 'output referenced in stack post step',
71+
additionalSetup: () => stackDeployment.addStackSteps([], [], [step]),
72+
expectedResultGetter: () => [outputName],
73+
},
74+
{
75+
description: 'output not referenced',
76+
additionalSetup: () => { },
77+
expectedResultGetter: () => [],
78+
},
79+
80+
];
81+
82+
cases.forEach(testCase => {
83+
test(testCase.description, () => {
84+
//WHEN
85+
testCase.additionalSetup();
86+
87+
//THEN
88+
expect(queries.stackOutputsReferenced(stackDeployment)).toEqual(testCase.expectedResultGetter());
89+
});
90+
});
91+
92+
});
93+
});
94+
95+
96+
class Blueprint extends cdkp.PipelineBase {
97+
protected doBuildPipeline(): void {
98+
}
99+
}

0 commit comments

Comments
 (0)
Please sign in to comment.