Slack Integration
Learn how to use flaky test webhooks to power Slack notifications
Last updated
Learn how to use flaky test webhooks to power Slack notifications
Last updated
Trunk allows you to create custom workflows to send customized messages to Slack through webhooks.
This guide will walk you through sending Slack messages using event-triggered webhooks. By the end of this tutorial, you'll receive Slack messages for test status changes. This guide should take 10 minutes to complete.
Trunk uses Svix to integrate with other services, such as Slack, through webhooks.
You can add the new Slack Webhook URL to Svix by following these steps:
Login to Trunk Flaky Tests
From your profile on the top right, navigate to Settings
Under Organization > Webhooks, click Slack
Click Connect to Slack and select the server and channel to connect to.
Review the transformation code automatically generated for GitHub issues. You can customize this transformation at any time. Learn more about customizing transformations.
By default, this connection will send messages about Trunk Merge and Flaky Tests events. If you only want Flaky Test events, unselect all events other than test_case.status_changed
.
Create the new endpoint. You will be redirected to the endpoint configuration view.
If you're having trouble adding a new webhook endpoint with Svix, please see the Adding Endpoint docs from Svix.
Transformations are custom code snippets you can write to customize the Slack messages sent by the webhook. A working template transformation will be added automatically for your webhook, but you can further customize the behavior of this webhook.
In the endpoint configuration view, navigate to the Advanced tab. Under Transformation, toggle the Enabled switch.
Click Edit transformation to update your transformation code, and click Save to update the transformation.
You can test the transformation by selecting the test_case.status_changed
payload and clicking Run Test. This will test the transformation but not send a message. You will learn to send a test message in step 3.
An example transformation script is provided below and you can customize your Slack integration by following the Slack and Svix transformations documentation.
You can send test messages to your Slack channels as you make updates. You can do this by:
In the endpoint configuration view, navigate to the Testing tab and select a Send event
Under Subscribed events, select test_case.status_changed
as the event type to send.
Click Send Example to test your webhook
You should now receive notifications in your Slack workspace when a test's status changes. You can further modify your transformation script to customize your messages.
See the Trunk webhook event catalog
You can monitor the events and the webhook's delivery logs in the Overview tab of an endpoint configuration view.
You can see an overview of how many webhook deliveries have been attempted, how many are successful, how many are in flight, and how many fail in the Attempt Delivery Status modal.
You can see a list of past delivery attempts in the Message Attempts modal. You can filter this list by Succeeded and Failed status, and you can click on each message to see the Message content, response code, and error message of each attempt. You can learn more about replaying messages and filtering logs in the Svix docs.