Using AWS to Send Buildkite Notifications to MS Teams
As of June 2024 Buildkite doesn’t have a method to natively integrate with MS Teams for Build notifications. In this blog we implement a method using AWS EventBridge with a Python Lambda function to send notifications to an MS Teams WebHook Endpoint
Introduction
Currently Buildkite does not support direct notifications to MS Teams. For those using buildkite in an Enterprise environment, this means building something custom.
This CloudFormation Template and Lambda function support Build Complete notifications to MS Teams using the Buildkite AWS EventBridge integration.
At the moment, the EventBus event has all the normal notification content, however it is missing the username sent in notifications sent using Slack. To implement this you would need to perform additional API calls to obtain this information.
Preparation
Create Buildkite AWS EventBridge Notification
EventBridge is one of 4 notification types currently offered by Buildkite
To Configure AWS EventBridge you will require the region and Account ID that you want your alerts deployed to. This will be the same account and region that you will deploy the CloudFormation template to shortly.
Once created, You will need the Partner event source name to deploy the CloudFormation Template Parameters.
Further Information - Buildkite Integrations - AWS EventBridge
Create an MS Teams ‘Incoming Webhook’ for Buildkite.
To Create the Webhook - Right click on the channel you want to have the Alerts sent to, and click on ‘Manage Channel’. Under connectors, click on ‘Edit’ under ‘Connectors’.
You will need to create a new ‘Incoming Webhook’ Connector. Enter the name, It is recommended to call this ‘Buildkite Notification’ or similar, and upload the buildkite.png as the image.
Save the WebHook URL for use with the CloudFormation Template in the next steps.
For Further information, refer to the Microsoft documentation
Further Information - Microsoft Teams Webhooks and Connectors
Deployment
Prepare Python Requirements
Install requirements for the Lambda function by running pip install from the function-msteams folder. This will install the pymsteams library and it’s dependencies. pip install -r requirements.txt -t .
Deploy the CloudFormation template
-
Using SAM or CloudFormation Build, build the template and deploy the Lambda function zip file
-
Deploy the Cloudformation Template
This will deploy the EventBus along with the rules and Lambda function. By default all events received from Buildkite are logged to ClooudWatch for you, and all Build Events are sent to the Lambda function to send the notifications.
- Enjoy your MS Teams Build Notifications
MS Teams Notifications
By default the lambda function will send Build Completed notifications for both success and failure, along with blocked notifications. Examples are shown below.
Source Code
The Source code for this project is available on GitHub https://github.com/steven-geo/buildkite-aws-msteams