How to send custom data generated from Bitbucket pipelines to Slack?
プラットフォームについて: Cloud のみ - この記事は、 クラウド プラットフォームのアトラシアン製品にのみ適用されます。
要約
It is possible to send customized messages or log files on Slack as notifications from Bitbucket pipeline builds using Pipes.
ソリューション
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
- 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.
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.