Customize the Slack notification
Asked by Ch?u Nguy?n Trung:

Hi,

I'm a newbie with Bitbucket. I used the default style of Bitbucket when integrating Bitbucket to Slack. I'm getting stuck in customizing the styles of notification when the Bitbucket pushing events messages to Slack channel. How could I customize it? I found Bitbucket has the Slack-notify pipe to customize but I want more as own badge, own icon, ...

Thanks


Answers:
author: Oleksandr Kyrdan
body: Hi [@Ch?u Nguy?n Trung](/t5/user/viewprofilepage/user-id/4424065) ,

Thank you for your question!

We provided [atlassian/slack-notify pipe](https://bitbucket.org/atlassian/slack-notify) where you could modify  
"pretext" and "text" sections in a payload of your slack message with PRETEXT and MESSAGE variables:  

```
- pipe: atlassian/slack-notify:1.0.2  variables:    WEBHOOK_URL: '<string>'    PRETEXT: '<string>'    MESSAGE: '<string>'    # DEBUG: '<boolean>' # Optional.
```

We'll discuss flexible payload with our team and notify you.

Cheers,  
Oleksandr Kyrdan


author: Oleksandr Kyrdan
body: Hi [@Ch?u Nguy?n Trung](/t5/user/viewprofilepage/user-id/4424065) ,

Now Flexible payload supported in [atlassian/slack-notify:1.2.0](https://bitbucket.org/atlassian/slack-notify):

```
script:  - envsubst < "payload.json.template" > "payload.json"  - pipe: atlassian/slack-notify:1.2.0    variables:      WEBHOOK_URL: $WEBHOOK_URL      PAYLOAD_FILE: payload.json?
```

Use custom payload created with [Slack Block Kit](https://api.slack.com/block-kit) and modify payload with the [envsubst](https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html) program that substitutes the values of environment variables.

Cheers,  
Oleksandr Kyrdan

comments: author: Peter Boling
body: But how do we get the environment variables into the script so that \`envsubst\` has access to them? I've tried everything I can think of, and read all the docs I can find, and very few ENV variables have values.  

Please give an example of a fully custom environment variable.  

For example, if I want a work log like this:  

```
- export WORK_LOG=`git log --pretty=format:"%h%x09%an%x09%ad%x09%s" "$BITBUCKET_COMMIT^..$BITBUCKET_COMMIT" | tail -n +2`
```

How can I get that \`$WORK_LOG\` variable into a payload or \`MESSAGE\`.  

This is one of the most frustrating things I've ever worked with.


author: Oleksandr Kyrdan
body: Hi [@Peter Boling](/t5/user/viewprofilepage/user-id/5374470)

Thanks for your question!

If you want substitutes the value of environment variable $WORK_LOG into payload file, you should have template file, i.e. **payload.json.template**

with name of the variable you want to invoke "$WORK_LOG"

after command executed

```
envsubst < "payload.json.template" > "payload.json"
```

you will have a new generated file "payload.json" with value of the "$WORK_LOG" variable.

Good example of envsubst [here](https://bitbucket.org/bitbucketpipelines/example-google-gke-kubectl-run/src/eb38fb8f620c734fddfb844e6af7e250c1ace617/bitbucket-pipelines.yml#lines-20) and [file](https://bitbucket.org/bitbucketpipelines/example-google-gke-kubectl-run/src/eb38fb8f620c734fddfb844e6af7e250c1ace617/helloweb-deployment.tpl.yaml#lines-20) .

Best regards,  
Oleksandr Kyrdan


Tags: bitbucket-pipelines

slack