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

Retrieved the title and the subject of the commit

Pierre KUHN 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

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 @Pierre KUHN 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, @Pierre KUHN !

Patrik S 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events