Setup pipeline stage slack notifications to send to specific slack channels (pipeline with multiple stages)

0

Is it possible to have slack notifications for a pipeline with multiple stages, where each stage sends notifications to a specific slack channel? Using the aws-cdk-lib/pipelines package.

1개 답변
0

Yes, it is possible to configure a CDK pipeline with multiple stages to send notifications to different Slack channels for each stage.

Here is an example of how you can do it in CDK:

const pipeline = new pipelines.CdkPipeline(this, 'Pipeline', {
  pipelineName: 'MyAppPipeline',
  
  stages: [
    {
      stageName: 'Source',
      actions: [/* source actions */],
      notifications: [
        new pipelines.SlackApproval(this, 'SourceSlackApproval', {
          notificationTopic: new sns.Topic(this, 'SourceTopic'),
          slackChannel: 'source-updates' 
        })  
      ]
    },
    {
      stageName: 'Build',
      actions: [/* build actions */], 
      notifications: [
        new pipelines.SlackApproval(this, 'BuildSlackApproval', {
          notificationTopic: new sns.Topic(this, 'BuildTopic'),
          slackChannel: 'build-notifications'
        })
      ]
    }
  ]
});

// Create SNS topic subscriptions
pipeline.stages[0].notifications[0].notificationTopic.subscribeUrl('https://hooks.slack.com/...'); 

pipeline.stages[1].notifications[0].notificationTopic.subscribeUrl('https://hooks.slack.com/...');

The key points:

  • Each stage can define its own notifications array with a SlackApproval

  • The SlackApproval is configured with a different SNS topic and slackChannel per stage

  • The SNS topics are then subscribed to separate Slack webhook URLs

This allows full customization of notifications for each stage in a CDK pipeline. The same approach could also be used for sending emails, PagerDuty alerts etc. per stage.

AWS
Saad
답변함 4달 전
  • Thanks for taking the time to answer. I'm new to CDK, but your sample looks to be CDK v1 related. I'm using v2. Maybe I'm not looking in the docs correctly, but where does SlackApproval come from? I don't see it anywhere in v1 or v2 docs.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠