aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.6k stars 3.89k forks source link

pipelines: Wrong action name when adding dependency between steps #21843

Closed bmmin closed 1 year ago

bmmin commented 2 years ago

Describe the bug

When a second stack's post action is a dependency of a first stack's post action, it incorrectly gets prefixed with the first stack's name

Expected Behavior

the prefix would not change when adding the dependency (e.g name should be fe.customFeDeployment)

Current Behavior

adding the dependency changes the prefix. (e.g name becomes be.customFeDeployment)

Reproduction Steps

Below is pipelines.ts. you need aws-cdk@1, ts-node, monocdk and typescript. Run

npx cdk --app "ts-node pipeline.ts" synth

Then you can see the generated steps with

jq '.Resources | to_entries[] | select(.value.Type=="AWS::CodePipeline::Pipeline") | .value.Properties.Stages[] | select(.Name=="stage") | .Actions[] | {runOrder:.RunOrder, Name:.Name}' cdk.out/PipelineStack.template.json
import { Construct, StackProps, Stage, StageProps } from "monocdk";
import { Stack } from "monocdk";
import { Repository } from "monocdk/aws-codecommit";
import { CodeBuildStep, CodePipeline, CodePipelineSource, StackSteps } from "monocdk/pipelines";
import { App } from "monocdk";

class PipelineStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);
    const repoInput = CodePipelineSource.codeCommit(Repository.fromRepositoryName(this, "Repository", "repo"), "mainline");
    const synthStep = new CodeBuildStep("Synth", {
      installCommands: [],
      commands: [],
      input: repoInput,
    });

    const pipeline = new CodePipeline(this, "Pipeline", {
      pipelineName: "Repro",
      synth: synthStep,
      crossAccountKeys: true,
    });

    const wave = pipeline.addWave("test");
    const stage = new TestStage(this, "stage");
    wave.addStage(stage, { stackSteps: stage.steps });
  }
}

class TestStage extends Stage {
    public steps: StackSteps[];
    constructor(scope: Construct, id: string, props?: StageProps) {
        super(scope, id, props);
        const be = new BeStack(this, "be");
        const e2eTests = new CodeBuildStep("e2eTests", { commands: ["echo test"] });
        const fe = new FeStack(this, "fe");
        const customFeDeployment = new CodeBuildStep("customFeDeployment", { commands: ["echo test"] });
        this.steps = [
            {stack: be, post: [e2eTests]},
            { stack: fe, post: [customFeDeployment]}
        ];
        e2eTests.addStepDependency(customFeDeployment);
    }    
}

class BeStack extends Stack {
    constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);
    }
}

class FeStack extends Stack {
    constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);
    }
}

const app = new App();
new PipelineStack(app, "PipelineStack");
app.synth();

Possible Solution

No response

Additional Information/Context

When removing the dependency (e.g comment out line 42: e2eTests.addStepDependency(customFeDeployment);), the name is correct

CDK CLI Version

1.169.0

Framework Version

No response

Node.js Version

v16.15.1

OS

macOs 12.5.1

Language

Typescript

Language Version

TypeScript (4.7.4)

Other information

No response

github-actions[bot] commented 1 year ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.