Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Sending a notification to Slack to notify\mention a specific user from Bitbucket pipeline

Andrei Hryharouski
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!
February 9, 2024

Good afternoon!
Can you please tell me if there is any way to send a message to Slack with the mention (@USERNAME) of a specific user?

The goal is to be able to send a message to the person in Slack who initiated the launch of the pipeline. This will perform a condition check at the end. For example:


- step: Some-step-name
    name: Some name
    script:
        - ...
        - if [ "$CHECK_ERRPR" != '"ERROR"' ]; then exit 0 ; fi
        - pipe: atlassian/slack-notify:2.3.0 variables: WEBHOOK_URL: $WEBHOOK_URL MESSAGE: '"[${ENVIRONMENT_NAME}] problem with something"'

 

I'd like to understand how when Bitbucket and Slack connect, messages can notify certain users, and I can't figure out how to identify user data (email for example) in the Bitbucket API with which I could identify the same user in Slack and get their ID using the Slack API.

2 answers

1 vote
Emel Doğrusöz February 19, 2024

Hey @Andrei Hryharouski ! 

 

There is a dedicated app for Bitbucket Pipelines management within Slack: https://actioner.com/app-directory/bitbucket-pipelines-15

 

It's fully customisable, too, with a generous free plan. Let me know in case you have any questions about this solution. 

 

Regards, 

Emel

1 vote
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 11, 2024

G'day @Andrei Hryharouski 

That's an interesting use case of slack pipe notification. I believe you can use the default variable we have to fetch the user that triggers the pipeline build UUID:

https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/

BITBUCKET_STEP_TRIGGERER_UUID

The person who kicked off the build ( by doing a push, merge etc), and for scheduled builds, the uuid of the pipelines user.

Using the UUID you can fetch the user information via the following API endpoint:

Get user 

You should get results of the user display_name that you can use with Slack API to mention the user. I can't help much on the Slack API end, but I believe you could create a script that fetches a user display name and matches it to get the user Slack ID stores it as variables, and uses it in the Slack pipe message notifications for example:

          script:
            - echo "Notify someone in Slack"
            - pipe: atlassian/slack-notify:2.3.0
              variables:
                  WEBHOOK_URL: '<Webhook>'
                  MESSAGE: 'Hey <@$slackID>' 

Regards,
Syahrul

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events