How to get logged in users email when running pipeline

Jani Ruohomaa December 16, 2020

Hi,

How do I get the email of the logged in user in bitbucket pipelines so that I can send email to the user with email-notify (https://bitbucket.org/atlassian/email-notify/src/master/)

I tried this:

curl -X GET -g "https://api.bitbucket.org/2.0/user/emails" | jq --raw-output '.values[0].email'

but it does not work. It seems it does not return anything

I also tried this endpoint but it does not contain the email address

https://api.bitbucket.org/2.0/users/{selected_user}

What is the context that the pipeline is run, it is not the logged in user ?

-Jani 

1 answer

1 accepted

0 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 16, 2020

Hi Jani,

I'm not really sure what you mean by 'logged in user in bitbucket pipelines'. Do you mean the user who triggered that build?

At the moment, I'm afraid that it is not possible to retrieve emails of other users via API.

Emails of workspace members are visible to workspace admins in workspace Settings >> User groups >> after selecting a specific User group.

However, they cannot be retrieved via API yet. We have an open feature request for this, you can add yourself as a watcher if you'd like to get notified via email on updates:

The API call you mention in your question:

curl -X GET -g "https://api.bitbucket.org/2.0/user/emails" | jq --raw-output '.values[0].email'

needs authentication.

You'll need to include in the call -u username:password with the credentials of your user. You could create repository variables for the username and password and then execute this call from the build, but it will return the email of your own user (that endpoint returns all the authenticated user's email addresses)

Kind regards,
Theodora

Jani Ruohomaa December 16, 2020

Yes, the user that is running the build. I was kind hoping that I could just call 

https://api.bitbucket.org/2.0/user/emails

and it would return me my email address since I am the one running the pipeline but I realized that I need to authenticate separately for that (with the same credentials that I logged in to bitbucket :-))

I assume you get the email from somewhere since if the pipeline fails I get an email that it has failed

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events