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

How can I trigger email notification on Pipeline build failure using the Email Notify pipe?

yosser_mahfoudh September 20, 2023

How do I add the logic to a pipe to check the build exit code and only send email upon failure?

2 answers

0 votes
yosser_mahfoudh September 28, 2023

I'm using the same script, but even the status is success the email is sent BUt I want onlt the email be sent when the step before is failed.

Otherwise how can I use my company email (generated from Mircosoft 365) to sen the email?

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 21, 2023

Hello @yosser_mahfoudh and welcome to the Community! 

You can use the pipeline default environment variable BITBUCKET_EXIT_CODE

The exit code of a step, can be used in after-script sections. Values can be 0 (success) or 1 (failed)

to create an if condition and check if the step is successful or not.

Following is an example of using that variable, along with the atlassian/email-notify, to send email notifications with the build status : 

      - step:
          name: Build and Test
            - echo "abc"
            - ALERT_TYPE="success"
            - if [[ $BITBUCKET_EXIT_CODE -ne 0 ]]; then ALERT_TYPE="error" ; fi
            - pipe: atlassian/email-notify:0.10.0
                USERNAME: ''
                PASSWORD: $PASSWORD
                FROM: ''
                TO: ''
                HOST: ''
                SUBJECT: '${ALERT_TYPE}:Bitbucket Pipe Notification for ${BITBUCKET_BRANCH}'

For further instructions on how to configure the variables required to execute that pipe, you can refer to its official documentation below :

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

Thank you, @yosser_mahfoudh !

Patrik S

Suggest an answer

Log in or Sign up to answer
Site Admin
AUG Leaders

Atlassian Community Events