Skip to content

Commit

Permalink
fix(pipelines): stack outputs used in stackSteps not recognized (#17311)
Browse files Browse the repository at this point in the history
fixes #17272


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
bmmin committed Nov 24, 2021
1 parent 5710fe5 commit 5e4a219
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
Expand Up @@ -17,6 +17,9 @@ export class PipelineQueries {
steps.push(...wave.pre, ...wave.post);
for (const stage of wave.stages) {
steps.push(...stage.pre, ...stage.post);
for (const stackDeployment of stage.stacks) {
steps.push(...stackDeployment.pre, ...stackDeployment.changeSet, ...stackDeployment.post);
}
}
}

Expand Down
@@ -0,0 +1,99 @@
/* eslint-disable import/no-extraneous-dependencies */
import '@aws-cdk/assert-internal/jest';
import * as cdkp from '../../../lib';
import { PipelineQueries } from '../../../lib/helpers-internal/pipeline-queries';
import { AppWithOutput, TestApp } from '../../testhelpers/test-app';

let app: TestApp;

beforeEach(() => {
app = new TestApp();
});

afterEach(() => {
app.cleanup();
});

describe('pipeline-queries', () => {

describe('stackOutputsReferenced', () => {
let blueprint: Blueprint;
let stageDeployment: cdkp.StageDeployment;
let step: cdkp.ShellStep;
let queries: PipelineQueries;
let stackDeployment: cdkp.StackDeployment;
let outputName: string | undefined;
beforeEach(() => {
blueprint = new Blueprint(app, 'Bp', {
synth: new cdkp.ShellStep('Synth', {
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
commands: ['build'],
}),
});
const stage = new AppWithOutput(app, 'CrossAccount');
outputName = 'MyOutput';
stageDeployment = blueprint.addStage(stage);
stackDeployment = stageDeployment.stacks[0];
expect(stackDeployment).not.toBeUndefined();
step = new cdkp.ShellStep('test', {
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
commands: ['build'],
envFromCfnOutputs: {
INPUT: stage.theOutput,
},
});
queries = new PipelineQueries(blueprint);
});

const cases = [
{
description: 'output referenced in stage pre step',
additionalSetup: () => stageDeployment.addPre(step),
expectedResultGetter: () => [outputName],
},
{
description: 'output referenced in stage post step',
additionalSetup: () => stageDeployment.addPost(step),
expectedResultGetter: () => [outputName],
},
{
description: 'output referenced in stack pre step',
additionalSetup: () => stackDeployment.addStackSteps([step], [], []),
expectedResultGetter: () => [outputName],
},
{
description: 'output referenced in stack changeSet step',
additionalSetup: () => stackDeployment.addStackSteps([], [step], []),
expectedResultGetter: () => [outputName],
},
{
description: 'output referenced in stack post step',
additionalSetup: () => stackDeployment.addStackSteps([], [], [step]),
expectedResultGetter: () => [outputName],
},
{
description: 'output not referenced',
additionalSetup: () => { },
expectedResultGetter: () => [],
},

];

cases.forEach(testCase => {
test(testCase.description, () => {
//WHEN
testCase.additionalSetup();

//THEN
expect(queries.stackOutputsReferenced(stackDeployment)).toEqual(testCase.expectedResultGetter());
});
});

});
});


class Blueprint extends cdkp.PipelineBase {
protected doBuildPipeline(): void {
}
}

0 comments on commit 5e4a219

Please sign in to comment.