Is there any way to add Manual approval action to CdkPipeline?

Viewed 1660

Hi I have created self mutating CDK pipeline for my infrastructure deployment.

I have added different application stages to this pipeline like Deploy to DEV, Deploy to UAT, Deploy to PROD Pipeline is working as expected and deploying changes to DEV -> UAT -> PROD environment but before deploying to UAT and PROD I would like to have manual Approval action so that changes will not deploy automatically to UAT and PROD there has to be manual approval action button after that button click changes should get promoted to higher environment.

I can find that option in code pipeline but I couldn't find such option in CdkPipeline construct.

Here is sample code -

const pipeline = new CdkPipeline(this, 'Pipeline', {
      // The main pipeline name
      pipelineName: 'Infra-Inception-Pipeline',
      cloudAssemblyArtifact,

      // Where the cdk source can be found
      sourceAction: new codepipeline_actions.CodeCommitSourceAction({
        actionName: "CloneCodeCommitRepo",
        repository: cdkSourceCodeRepo,
        output: cdkSourceOutput,
        // branch: "develop"
      }),

      // How will cdk be built and synthesized
      synthAction: SimpleSynthAction.standardNpmSynth({
        sourceArtifact: cdkSourceOutput,
        cloudAssemblyArtifact,
        // We need a build step to compile the TypeScript 
        buildCommand: 'npm run build'
      }),
    });

pipeline.addApplicationStage(new CreateInfrastructureStage(this, 'DEV',
     {
       env: { "account":"1111" "region":"us-east-1" }
     }));

//I would like to add Manual Approval gate here

pipeline.addApplicationStage(new CreateInfrastructureStage(this, 'UAT',
     {
       env: { "account":"2222" "region":"us-east-1" }
     }));

1 Answers

I found the answer in AWS documentation.

Every application stage added by addApplicationStage() leads to the addition of an individual pipeline stage, which is returned by the addApplicationStage() call. This stage is represented by the CdkStage construct. You can add more actions to the stage by calling its addActions() method. For example:

    // import { ManualApprovalAction } from '@aws-cdk/aws-codepipeline-actions';

const testingStage = pipeline.addApplicationStage(new MyApplication(this, 'Testing', {
  env: { account: '111111111111', region: 'eu-west-1' }
}));

// Add an action -- in this case, a Manual Approval action
// (testingStage.addManualApprovalAction() is an equivalent convenience method)
testingStage.addActions(new ManualApprovalAction({
  actionName: 'ManualApproval',
  runOrder: testingStage.nextSequentialRunOrder(),
}));
Related