From b0e55094ce098f0d3d3777dd688fbffea729a699 Mon Sep 17 00:00:00 2001 From: William Putra Intan <61998484+williamputraintan@users.noreply.github.com> Date: Thu, 7 Mar 2024 09:54:56 +1100 Subject: [PATCH] codepipeline notication (#130) --- .../orcabus-stateful-pipeline-stack.ts | 26 +++++++++++++++++ .../orcabus-stateless-pipeline-stack.ts | 28 ++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/lib/pipeline/orcabus-stateful-pipeline-stack.ts b/lib/pipeline/orcabus-stateful-pipeline-stack.ts index df4d34d86..ccc0e395e 100644 --- a/lib/pipeline/orcabus-stateful-pipeline-stack.ts +++ b/lib/pipeline/orcabus-stateful-pipeline-stack.ts @@ -4,6 +4,9 @@ import * as ssm from 'aws-cdk-lib/aws-ssm'; import * as pipelines from 'aws-cdk-lib/pipelines'; import * as codebuild from 'aws-cdk-lib/aws-codebuild'; import * as iam from 'aws-cdk-lib/aws-iam'; +import * as codepipeline from 'aws-cdk-lib/aws-codepipeline'; +import * as chatbot from 'aws-cdk-lib/aws-chatbot'; +import * as codestarnotifications from 'aws-cdk-lib/aws-codestarnotifications'; import { OrcaBusStatefulConfig, OrcaBusStatefulStack } from '../workload/orcabus-stateful-stack'; import { getEnvironmentConfig } from '../../config/constants'; @@ -108,6 +111,29 @@ export class StatefulPipelineStack extends cdk.Stack { }), { pre: [new pipelines.ManualApprovalStep('PromoteToProd')] } ); + + // need to build pipeline so we could add notification at the pipeline construct + pipeline.buildPipeline(); + + // notification for success/failure + const arteriaDevSlackConfigArn = ssm.StringParameter.valueForStringParameter( + this, + '/chatbot_arn/slack/arteria-dev' + ); + const target = chatbot.SlackChannelConfiguration.fromSlackChannelConfigurationArn( + this, + 'SlackChannelConfiguration', + arteriaDevSlackConfigArn + ); + + pipeline.pipeline.notifyOn('PipelineSlackNotification', target, { + events: [ + codepipeline.PipelineNotificationEvents.PIPELINE_EXECUTION_FAILED, + codepipeline.PipelineNotificationEvents.PIPELINE_EXECUTION_SUCCEEDED, + ], + detailType: codestarnotifications.DetailType.BASIC, + notificationRuleName: 'orcabus_stateful_pipeline_notification', + }); } } diff --git a/lib/pipeline/orcabus-stateless-pipeline-stack.ts b/lib/pipeline/orcabus-stateless-pipeline-stack.ts index 0cd353581..771e676e9 100644 --- a/lib/pipeline/orcabus-stateless-pipeline-stack.ts +++ b/lib/pipeline/orcabus-stateless-pipeline-stack.ts @@ -4,6 +4,9 @@ import * as ssm from 'aws-cdk-lib/aws-ssm'; import * as pipelines from 'aws-cdk-lib/pipelines'; import * as codebuild from 'aws-cdk-lib/aws-codebuild'; import * as iam from 'aws-cdk-lib/aws-iam'; +import * as chatbot from 'aws-cdk-lib/aws-chatbot'; +import * as codepipeline from 'aws-cdk-lib/aws-codepipeline'; +import * as codestarnotifications from 'aws-cdk-lib/aws-codestarnotifications'; import { OrcaBusStatelessConfig, OrcaBusStatelessStack } from '../workload/orcabus-stateless-stack'; import { getEnvironmentConfig } from '../../config/constants'; @@ -129,10 +132,33 @@ export class StatelessPipelineStack extends cdk.Stack { // if (!prodConfig) throw new Error(`No 'Prod' account configuration`); // pipeline.addStage( // new OrcaBusStatelessDeploymentStage(this, 'ProdStatelessDeployment', prodConfig.stackProps, { - // account: gammaConfig?.accountId, + // account: prodConfig?.accountId, // }), // { pre: [new pipelines.ManualApprovalStep('PromoteToProd')] } // ); + + // need to build pipeline so we could add notification at the pipeline construct + pipeline.buildPipeline(); + + // notification for success/failure + const arteriaDevSlackConfigArn = ssm.StringParameter.valueForStringParameter( + this, + '/chatbot_arn/slack/arteria-dev' + ); + const target = chatbot.SlackChannelConfiguration.fromSlackChannelConfigurationArn( + this, + 'SlackChannelConfiguration', + arteriaDevSlackConfigArn + ); + + pipeline.pipeline.notifyOn('PipelineSlackNotification', target, { + events: [ + codepipeline.PipelineNotificationEvents.PIPELINE_EXECUTION_FAILED, + codepipeline.PipelineNotificationEvents.PIPELINE_EXECUTION_SUCCEEDED, + ], + detailType: codestarnotifications.DetailType.BASIC, + notificationRuleName: 'orcabus_stateless_pipeline_notification', + }); } }