How do I add the logic to a pipe to check the build exit code and only send email upon failure?
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.