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

i want to send email to developer after the deployment, it may be successful or failed how can do it

amol funde February 8, 2022

i have written a yml for that just configured ec2 details after that i need to send an email to developers that depolyment is done with the status failed r sucess.

image: atlassian/default-image:3

pipelines:
default:
- parallel:
- step:
name: 'Build and Test'
script:
- echo "Your build and test goes here.."
- step:
name: 'Lint'
script:
- echo "Your linting goes here..."
- step:
name: 'Security scan'
script:
- echo "Your security scan goes here..."

# The following deployment steps will be executed for each pipeline run. To configure your steps and conditionally deploy see https://support.atlassian.com/bitbucket-cloud/docs/configure-bitbucket-pipelinesyml/
- step:
name: 'Deployment to Staging'
deployment: staging
script:
- pipe: atlassian/ssh-run:0.4.0
variables :
SSH_USER: '******'
SERVER: '*************'
COMMAND: 'mkdir test21'
- step :
name: 'email notifications'
script:
- ALERT_TYPE="success"
- if [[ $BITBUCKET_EXIT_CODE -ne 0 ]]; then ALERT_TYPE="error" ; fi
- pipe: 'atlassian/email-notify:0.5.0'
variables :
USERNAME: '$SOME_USERNAME'
PASSWORD: $PASSWORD
FROM: 'noreply@atlassian.com'
TO: '$SOME_EMAIL_TO'
HOST: 'smtp.gmail.com'
PORT: '25'
SUBJECT: '${ALERT_TYPE}:Bitbucket Pipe Notification for ${BITBUCKET_BRANCH}'

 

1 answer

1 vote
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 13, 2022

Hi @amol funde

Welcome to the community.

For you to be able to run scripts on Pipelines regardless if the build is failed or successful, you can use the configuration called "after-script".
After-script will allow you to run commands at the end of a step execution.

For your current YAML configuration, you'll just need to add the step "email notifications" as an after-script of the step "Deployment to Staging".

Your "Deployment to Staging" step, should look like below:

      - step:
          name: 'Deployment to Staging'
          deployment: staging
          script:
            - pipe: atlassian/ssh-run:0.4.0
              variables :
                SSH_USER: '******'
                SERVER: '*************'
                COMMAND: 'mkdir test21'
          after-script:
            - ALERT_TYPE="success"
            - if [[ $BITBUCKET_EXIT_CODE -ne 0 ]]; then ALERT_TYPE="error" ; fi
            - pipe: 'atlassian/email-notify:0.5.0'
              variables :
                USERNAME: '$SOME_USERNAME'
                PASSWORD: $PASSWORD
                FROM: '$SOME_EMAIL_FROM'
                TO: '$SOME_EMAIL_TO'
                HOST: 'smtp.gmail.com'
                PORT: '25'
                SUBJECT: '${ALERT_TYPE}:Bitbucket Pipe Notification for ${BITBUCKET_BRANCH}'

Hope it helps and let me know how it goes.

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events