Customize the Slack notification

Châu Nguyễn Trung
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 4, 2021

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

2 answers

1 vote
Oleksandr Kyrdan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 7, 2021

Hi @Châu Nguyễn Trung ,

Thank you for your question!

We provided atlassian/slack-notify pipe 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

0 votes
Oleksandr Kyrdan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 26, 2021

Hi @Châu Nguyễn Trung ,

Now Flexible payload supported in atlassian/slack-notify:1.2.0:

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 and modify payload with the envsubst program that substitutes the values of environment variables.

 

Cheers,
Oleksandr Kyrdan

Peter Boling March 20, 2024

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.

Oleksandr Kyrdan
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 22, 2024

Hi @Peter Boling 

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 and file .

 

Best regards,
Oleksandr Kyrdan

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events