aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

Code Pipeline: Stage(step) skipping condition support

Open pitayapj opened this issue 2 years ago • 6 comments

Describe the feature

Pretty early but code pipeline now support skipping stage base on various of condition. One of them is variable's value and it would be so much helpful if CDK support it.

https://aws.amazon.com/about-aws/whats-new/2024/10/aws-codepipeline-skipping-stage/

According to docment below, CF already supporting it https://docs.aws.amazon.com/codepipeline/latest/userguide/stage-conditions.html#stage-conditions-onsuccess

Use Case

I want to use pipeline variable and skipping stage base on it.

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

CDK version used

2

Environment details (OS name and version, etc.)

MacOS

pitayapj avatar Nov 07 '24 09:11 pitayapj

ashishdhingra avatar Nov 07 '24 19:11 ashishdhingra

@ashishdhingra thank you for your response. I actually want to skip a stage, not condition it with onSuccess and onFailure.

I can see that beforeEntry is also supported but my actions are written is L3, can you tell me how to integrate it with StageDeclarationProperty ?

const pipeline = new codepipeline.Pipeline(this, "pipeline", {
      stages: [
        {
          stageName: "Source",
          actions: [sourceAction],
        },
        {
          stageName: "Build",
          actions: [
            new codepipeline_actions.CodeBuildAction({
              project: buildProject,
              input: sourceOutput,
              outputs: [buildOutput],
              variablesNamespace: "BuildImage"
            }),
          ],    
        },
        // skip this if #{BuildImage.MIGRATION_FLAG} = false
        {
          stageName: "Migration",
          actions: [
            new codepipeline_actions.CodeBuildAction({
              actionName: "Run_Migration",
              project: runMigrationBuild,
              input: buildOutput, // Pass build output with imageDetail.json
            }),
          ],
        },
       ]
});

pitayapj avatar Nov 08 '24 03:11 pitayapj

I was able to create L3 pipeline then extent with L1 contruct as following. But, still nicer if we can have L3 contruct support stage condition.

const l1Pipeline = pipeline.node.defaultChild as codepipeline.CfnPipeline;

l1Pipeline.addOverride('Properties.Stages.2.BeforeEntry', {
  Conditions: [
    {
      Result: "SKIP",
      Rules: [
          {
            Name: "Skip_Migration",
            RuleTypeId: {
              Category: "Rule",
              Owner: "AWS",
              Provider: "VariableCheck",
              Version: "1"
            },
            Configuration: {
              Variable: "#{BuildImage.MIGRATION_FLAG}",
              Value: "false",
              Operator: "EQ"
            },
          }
      ]
    }
  ]
});

pitayapj avatar Nov 08 '24 07:11 pitayapj

Just want to add something. Additions of L3 construct for both codepipeline and cdk pipeline would be amazing.

pitayapj avatar Dec 25 '24 03:12 pitayapj

feature implemented: https://github.com/aws/aws-cdk/issues/33511#issuecomment-2753044920

document: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.StageProps.html

pitayapj avatar Apr 08 '25 06:04 pitayapj

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

github-actions[bot] avatar Apr 08 '25 06:04 github-actions[bot]