Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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

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

4 answers

1 accepted

3 votes
Answer accepted

Hi @Doug Harriman , 

You should be able to check the exist code of the pipeline step in the after-script section of the step


    - step:
        name: Build and test
          - npm install
          - npm test
          - if [[ BITBUCKET_EXIT_CODE -eq 0 ]]; then exit 0; else echo "Step failed"
- pipe: atlassian/email-notify:0.3.8
FROM: ''
TO: ''
HOST: ''
BODY_PLAIN: "Build failed!"

The BITBUCKET_EXIT_CODE variable is available in the after-script. The value will be 0 of the step is successful and 1 if the step has failed. 



We tried to implement this suggestion, but get the following error : 

if [[ BITBUCKET_EXIT_CODE -eq 0 ]]; then exit 0; else echo "Step failed";bash: /opt/atlassian/pipelines/agent/tmp/ line 96: syntax error: unexpected end of file


Any input would be appreciated.



Like Georgi Vladov likes this

Me too:


Fixes adding "fi":


if [[ BITBUCKET_EXIT_CODE -eq 0 ]]; then exit 0else echo "Step failed" fi
Like Radoslav Dragijev likes this

Did not work for me. Any other approach?

0 votes

If anyone is still struggling to get the above snippet to work.


You can turn on notifications from the repo itself in Bitbucket.


1. Go the repository you want to monitor

2. On the Source tab, click the ellipsis and select Manage Notifications

3. Click Watch this repository


Now when a pipeline fails you should get an email alert 

I thought I should be posting my question as a separate one so moving it to a separate thread here How to configure email notifications using Microso... (



Hi @Alexander Zhukov ,

I am also getting same error like...

if [[ BITBUCKET_EXIT_CODE -eq 0 ]]; then exit 0; else echo "Step failed"bash: /opt/atlassian/pipelines/agent/tmp/ line 94: syntax error: unexpected end of file


Also i have tried @Goinnn 's trick, but i didn't work for me. Please help me.


I'm a bit late but try this:

if [[ BITBUCKET_EXIT_CODE -eq 0 ]]; then exit 0else echo "Step failed"; fi;

Also, did you get this implemented?

In the logs it says "Sending email..." and then "✖ Failed to send email to <TO-email>. Check your configuration settings."

What needs to be filled in 'username' and 'from' fields?

Dear did you able to fix this issue 
because I am getting the same error 
"failed to send email check your configuration setting "

In the logs it says "Sending email..." and then "✖ Failed to send email to <TO-email>. Check your configuration settings."


getting same can some help if its working for them.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

3,487 views 3 10
Read article

Atlassian Community Events