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

(info) Check out these Pre-requisites in Slack

  1. Create an application in Slack
    • Select the option "From Scratch"
    • Enter the App Name
    • Pick a workspace to Select a workspace"
  2. Open the App you have created
    • From the settings, select "Incoming webhooks"
    • Enable "Activate Incoming Webhooks"
  3. Once you have enabled it,
    • Click on "Add New Webhook to Workspace"
    • Choose the channel in which the notification needs to be sent.
  4. Copy the webhook URL at the bottom of the screen.

Setting up things in Bitbucket

  1. You can use Slack-notify pipe for this use case.
  2. 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.
  3. 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. 


最終更新日: 2024 年 1 月 26 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.