How to send custom data generated from Bitbucket pipelines to Slack?
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
It is possible to send customized messages or log files on Slack as notifications from Bitbucket pipeline builds using Pipes.
Solution
In order to achieve these you need to configure Slack apps with webhooks and bitbucket pipes.
Setting up things in Slack
ℹ️ Check out these Pre-requisites in Slack
Create an application in Slack
Select the option "From Scratch"
Enter the App Name
Pick a workspace to develop your app in "Select a workspace"
Open the App you have created
From the settings, select "Incoming webhooks"
Enable "Activate Incoming Webhooks"
Once you have enabled it,
Click on "Add New Webhook to Workspace"
Choose the channel in which the notification needs to be sent.
Copy the webhook URL at the bottom of the screen.
Setting up things in Bitbucket
You can use Slack-notify pipe for this use case.
Open the repository settings
Add the secure variable SLACK_WEBHOOK_URL for the name.
Add the copied webhook URL generated from Slack as a value.
Edit the pipeline YAML file accordingly. For example, the below pipeline will send the logs saved in the logs.txt file as a message to Slack using a Slack-notify pipe.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
pipelines: default: - step: name: Build artifacts: - logs.txt script: - echo "Build Steps" - echo "added some logs" >> logs.txt - step: name: Message to Slack script: - pipe: atlassian/slack-notify:2.0.0 variables: WEBHOOK_URL: $SLACK_WEBHOOK_URL MESSAGE: '$(cat logs.txt)'
With this setup, you can send custom data generated by your Bitbucket pipelines as a notification message to your Slack channel.

Was this helpful?