The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieved the title and the subject of the commit

Deleted user
August 30, 2023

Good morning,

 

How to put the commit title in the subject or body of the email?

Do you have a sample page?

Thank

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 31, 2023

Hello @[deleted] and thank you for reaching out to the Community!

From your description, I assume you are using the atlassian/email-notify pipe.

While there's no default environment variable in the pipeline containing the commit message, you can use the $BITBUCKET_COMMIT env variable to get the commit message using the below git command : 

git log --format=%B -n 1 $BITBUCKET_COMMIT

and then export the output of that command (the commit message) to a new custom environment variable.

export COMMIT_MESSAGE=$(git log --format=%B -n 1 $BITBUCKET_COMMIT)

All the default env variables and any custom env variable you create during the step are available inside the pipe and can be referenced as you would normally do in the script.

Using the concept above, following is an example of including the commitID and commit message to both the Subject and Body of the email message : 

pipelines:
  default:
    - step:
       script:
         - git log --format=%B -n 1 $BITBUCKET_COMMIT
         - export COMMIT_MESSAGE=$(git log --format=%B -n 1 $BITBUCKET_COMMIT)
         - echo $COMMIT_MESSAGE
         - pipe: atlassian/email-notify:0.9.0
           variables:
             USERNAME: 'myemail@email.com'
             PASSWORD: $MAIL_PASS
             FROM: 'myemail@email.com
             TO: 'myemail@email.com'
             HOST: 'smtp.gmail.com' 
             SUBJECT: 'Email for commit $BITBUCKET_COMMIT - $COMMIT_MESSAGE'
             BODY_PLAIN: 'Email send from Bitbucket Pipeline executed on commit $BITBUCKET_COMMIT - $COMMIT_MESSAGE'

Hope that helps! Let me know in case you have any questions.

Thank you, @[deleted] !

Patrik S 

DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events