Skip to content

cleverly-ai/code-pipeline-slack

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Pipeline Slack Bot

This bot will notify you of CodePipeline progress (using CloudWatch Events).

We attempt to provide a unified summary, by pulling together multiple events, as well as information obtained by the API into a single message view.

Build

Fork changes

  • fixed issues (original code gave errors, slack api updates + code issues)
  • private channels support added

Configuration / Customization

No configuration is necessary per pipeline. As part of the CF Stack, we subscribe to all CodePipeline and CodeBuild events (using CloudWatch Events).

When creating the CloudFormation stack, you can customize:

  • SlackChannel (defaults to builds).
  • SlackChannelType (defaults to public).
  • SlackBotName (defaults to PipelineBuildBot).
  • SlackBotIcon (defaults to :robot_face: 🤖 ).

Additionally, you must provide slack OAuth tokens (check next section on how to get it)

  • SlackOAuthAccessToken
  • SlackBotUserOAuthAccessToken

If you have the legacy integration token, just add that token to both fields.

Slack configuration

  • create an app (or use existing app)
  • create a bot user (see BotUsers for creating a slack bot user with an OAuth token)
  • specify following scopes on your slack application OAuth & Permissions page:
    • channels:history (to search messages in public channels)
    • groups:history (to search messages in private channels)
    • bot (ability to invite bot to channels)
  • add bot user to the desired channel
  • copy OAuth tokens into CloudFormation stack

How it works

We utilize CloudWatch Events for CodePipline and CodeBuild to get notified of all status changes.

Using the notifications, as well as using the CodePipeline APIs, we are able to present a unified summary of your Pipeline and Build status.

IAM permissions

As part of the deployment, we create an IAM policy for the bot lambda function of:

Policies:
  - AWSLambdaBasicExecutionRole
  - Version: '2012-10-17'
    Statement:
      - Effect: Allow
        Action:
          - 'codepipeline:Get*'
          - 'codepipeline:List*'
        Resource: '*'
      - Effect: Allow
        Action:
          - 'codebuild:Get*'
        Resource: '*'

So we can retrieve information about all pipelines and builds. See template.yml for more detail.

Deploying

  1. Ensure you have pipenv installed
  • which pipenv || pip3 install pipenv
  1. (Optional) Save a backup of the current version
  • AWS Console: Actions -> Export function
  • curl -LO "$(aws lambda get-function --function-name $LAMBDA_FUNCTION_NAME | jq -r '.Code.Location')"
  1. Generate a package with the new version
  • TARGET_FOLDER=$PWD/output ZIP_FILE='code-pipeline-slack.zip' ./package.sh
  1. Upload the new package
  • AWS Console: Function Code -> Actions -> Upload a .zip file
  • aws lambda update-function-code --function-name $LAMBDA_FUNCTION_NAME --zip-file fileb://code-pipeline-slack.zip

About

Slack bot for code pipeline deployments

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 93.5%
  • Shell 6.5%