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.
- fixed issues (original code gave errors, slack api updates + code issues)
- private channels support added
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 tobuilds
).SlackChannelType
(defaults topublic
).SlackBotName
(defaults toPipelineBuildBot
).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.
- 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
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.
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.
- Ensure you have pipenv installed
which pipenv || pip3 install pipenv
- (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')"
- Generate a package with the new version
TARGET_FOLDER=$PWD/output ZIP_FILE='code-pipeline-slack.zip' ./package.sh
- 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