Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codepipeline & codestart notification: unable to associate the source for the code pipeline on a notification #27078

Open
akhilpatlolla opened this issue Sep 8, 2023 · 5 comments
Labels
@aws-cdk/aws-codepipeline Related to AWS CodePipeline bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@akhilpatlolla
Copy link

akhilpatlolla commented Sep 8, 2023

Describe the bug

We are trying to create Code Pipeline and associate notifications to the code pipeline. Code pipelines got created sucessfully but when trying to associate a notification to it there are multiple issue and also the notification-rule-source.d.ts interface is confusing as well.

described 4 options here with 4 different version of soruce

option 1 : source: pipeline.pipeline,
option 2 : source: pipeline.pipeline.bindAsNotificationRuleSource(this),
option 3 : source: notificationRuleSourceConfig,
option 4 : source: pipelineSource,

code-pipeline.ts

import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
import {
  CodePipeline,
  CodePipelineSource,
  ManualApprovalStep,
  ShellStep,
} from "aws-cdk-lib/pipelines";
import { Options } from "../../types";
import { CodePipelineStage } from "./application-stack";
import { Stage } from "../app.config";
import { BuildSpec, LinuxBuildImage } from "aws-cdk-lib/aws-codebuild";
import * as notifications from "aws-cdk-lib/aws-codestarnotifications";
import * as sns from "aws-cdk-lib/aws-sns";


export class CodePipelineStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: PipelineStackProps) {
    const pipeline = new CodePipeline(this, `${prefix}-codepipeline`, {
      pipelineName: `${prefix}-codepipeline`,
      crossAccountKeys: true,
      codeBuildDefaults: {
        buildEnvironment: {
          buildImage: LinuxBuildImage.STANDARD_7_0,
        },
      },
      selfMutation: false,
      synth: new ShellStep("Synth", {
        input: CodePipelineSource.connection(repoString, branch, {
          connectionArn,
        }),
        // installCommands: ["npm i"],
        commands: ["cd cdkv2", "npm ci", "npx cdk synth"],
        primaryOutputDirectory: "cdkv2/cdk.out",
      }),

      synthCodeBuildDefaults: {
        buildEnvironment: {
          buildImage: LinuxBuildImage.STANDARD_7_0,
        },
        partialBuildSpec: BuildSpec.fromObject({
          phases: {
            install: {
              "runtime-versions": {
                nodejs: "18",
              },
            },
          },
        }),
      },
    });


   // trying other options as well here 

  const notificationRuleSourceConfig: notifications.NotificationRuleSourceConfig = {
      sourceArn:  pipeline.pipeline.pipelineArn,
    };

    const pipelineSource: notifications.INotificationRuleSource = {
      bindAsNotificationRuleSource: (scope: Construct) => {
        return notificationRuleSourceConfig;
      },
    };


  
    // pipeline.buildPipeline();
    new notifications.NotificationRule(
      this,
      `${props.stage}-CodePipelineMonitoringRule`,
      {
        
        // source: pipeline.pipeline, 
        // option 1
        // error : lib/codepipeline/code-pipeline-monitoring.ts:59:9 - error TS2741: Property 'bindAsNotificationRuleSource' is missing in type 'typeof CodePipeline' but required in type 'INotificationRuleSource'.


        source: pipeline.pipeline.bindAsNotificationRuleSource(this),
        // option 2
        // error : Property 'bindAsNotificationRuleSource' is missing in type 'NotificationRuleSourceConfig' but required in type 'INotificationRuleSource'.ts(2741) notification-rule-source.d.ts(19, 5): 'bindAsNotificationRuleSource' is declared here. notification-rule.d.ts(60, 14): The expected type comes from property 'source' which is declared here on type 'NotificationRuleProps'


        // source: notificationRuleSourceConfig,
        // option 3
        // error : Property 'bindAsNotificationRuleSource' is missing in type 'NotificationRuleSourceConfig' but required in type 'INotificationRuleSource'.ts(2741) notification-rule-source.d.ts(19, 5): 'bindAsNotificationRuleSource' is declared here. notification-rule.d.ts(60, 14): The expected type comes from property 'source' which is declared here on type 'NotificationRuleProps'



        // source: pipelineSource,
        // option 4
        // error : lib/codepipeline/code-pipeline-monitoring.ts:59:9 - error TS2741: Property 'bindAsNotificationRuleSource' is missing in type 'typeof CodePipeline' but required in type 'INotificationRuleSource'.


        events: [
          "codebuild-project-build-state-failed",
          "codebuild-project-build-phase-failure",
          "codedeploy-application-deployment-failed",
          "codepipeline-pipeline-action-execution-failed",
          "codepipeline-pipeline-stage-execution-failed",
          "codepipeline-pipeline-pipeline-execution-failed",
        ],
        targets: [PDTopic],
      }
    );
  }
}

notification-rule-source-d.ts

import * as constructs from 'constructs';
/**
 * Information about the Codebuild or CodePipeline associated with a notification source.
 */
export interface NotificationRuleSourceConfig {
    /**
     * The Amazon Resource Name (ARN) of the notification source.
     */
    readonly sourceArn: string;
}
/**
 * Represents a notification source
 * The source that allows CodeBuild and CodePipeline to associate with this rule.
 */
export interface INotificationRuleSource {
    /**
     * Returns a source configuration for notification rule.
     */
    bindAsNotificationRuleSource(scope: constructs.Construct): NotificationRuleSourceConfig;
}

Expected Behavior

expected to associate pipeline seamlessly to the notification.

Current Behavior

it's throwing bunch of errors.

Reproduction Steps

create a code pipeline and try to attach a code star notification to it using the pipeline object once it's created.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

[email protected] cdk

Framework Version

No response

Node.js Version

18

OS

mac os

Language

Typescript

Language Version

typescript 8.15

Other information

No response

@akhilpatlolla akhilpatlolla added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 8, 2023
@github-actions github-actions bot added the @aws-cdk/aws-codepipeline Related to AWS CodePipeline label Sep 8, 2023
@akhilpatlolla
Copy link
Author

akhilpatlolla commented Sep 8, 2023

Other alternative approches suggested was to use pipeline.buidlpipeline() and pipeline.pipeline as an input for source but that doesn't work either.

@indrora
Copy link
Contributor

indrora commented Sep 11, 2023

Is this related to #9710 ? @TheRealAmazonKendra does this look similar?

@peterwoodworth
Copy link
Contributor

@indrora could you dive deep into this yourself?

@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Sep 13, 2023
@akhilpatlolla
Copy link
Author

any update on the issue ? @peterwoodworth / @indrora

@mascalucianppb
Copy link

Are there news related to this issue?
Referencing existing pipelines using NotificationsRule CDK construct still doesn't seem to work.

@peterwoodworth @indrora

@pahud pahud added p2 effort/medium Medium work item – several days of effort labels Nov 30, 2023
@pahud pahud assigned pahud and unassigned indrora and pahud Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codepipeline Related to AWS CodePipeline bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

5 participants