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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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?

2 answers

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.
Sep 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 : 

pipelines:
  default:
      - step:
          name: Build and Test
          script:
            - echo "abc"
          after-script:
            - ALERT_TYPE="success"
            - if [[ $BITBUCKET_EXIT_CODE -ne 0 ]]; then ALERT_TYPE="error" ; fi
            - pipe: atlassian/email-notify:0.10.0
              variables:
                USERNAME: 'myemail@example.com'
                PASSWORD: $PASSWORD
                FROM: 'myemail@example.com'
                TO: 'example1@example.com'
                HOST: 'smtp.gmail.com'
                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
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events