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
4,364,000
Community Members
 
Community Events
168
Community Groups

Send notification if build failure log contains specific error message or code

Hi,

I have a Bitbucket pipeline which internally calls different APIs for authentication and other functionalities. I want to get notification for all the pipeline failures. But if the failure log contains specific error message or error code, I would like send a notification to other teams as well. These team may change base based on the error code/message.

Is there a way to achieve this scenario in Bitbucket pipeline.

2 answers

Hi @Devendra Sharma 

Good question!

Also, you can use $BITBUCKET_EXIT_CODE variable in the after-script section.

$BITBUCKET_EXIT_CODE - the exit code of a step, if step success value setup to 0

with pipes for notification, alerting, monitoring

atlassian/datadog-send-event

script:
- <some build logic>
after-script:
- ALERT_TYPE="success"
- if [[ $BITBUCKET_EXIT_CODE -ne 0 ]]; then ALERT_TYPE="error" ; fi
- pipe: atlassian/datadog-send-event:1.1.2
variables:
API_KEY: $API_KEY
ALERT_TYPE: $ALERT_TYPE

or atlassian/email-notify

build: &build
step:
name: Build
script:
- echo "Starting build..."
#- <your build logic>
after-script:
- ALERT_TYPE="success"
- if [[ $BITBUCKET_EXIT_CODE -ne 0 ]]; then ALERT_TYPE="error" ; fi
- pipe: atlassian/email-notify:0.3.12
variables:
USERNAME: 'myemail@example.com'
PASSWORD: $PASSWORD
FROM: 'myemail@example.com'
TO: 'example1@example.com, example2@example.com'
HOST: 'smtp.gmail.com'
SUBJECT: '${ALERT_TYPE}:Bitbucket Pipe Notification for ${BITBUCKET_BRANCH}'

 

To discover more pipes, visit Bitbucket Pipes Marketplace.

 

Best regards,
Oleksandr Kyrdan

0 votes
Syahrul Atlassian Team Jan 03, 2022

Hi @Devendra Sharma

G'Day!

Currently, we don't have the feature to create a custom email notification for specific error messages in Bitbucket pipeline build logs.

 

We only sent email notification for failed build at this moment, but I have proceeded to raise a feature request on behalf of you, please Vote and Watch  the feature request so that you'll receive an update whenever we have any at:

I hope this helps.

Cheers,
Syahrul

@Syahrul Hello Folks, Is this issue fixed?

What I'm looking for in the pipeline? I'm running a set of Terraform commands in the bit bucket pipeline, Which will kick off commands one after another: 

 

Terraform init

Terraform validate

Terraform plan

  1. Plan success-> send an email to a list of users->
  2. Wait for approval that has been created Via..,  "Jira service management"
  3. maybe a Day/2 and <Once approved, the pipeline has to kick the tf apply command.
  4. Once the approved button is hit, Pipeline should have to run the "terraform apply".

Which i followed link on internet: 

1. @o_kyrdan Is this worked? 
https://community.atlassian.com/t5/Bitbucket-questions/Send-notification-if-build-failure-log-contains-specific-error/qaq-p/1878124

2. @Syahrul  Will this works?
https://community.atlassian.com/t5/Bitbucket-questions/Bitbucket-Pipelines-amp-approvals/qaq-p/1659160

       i. https://bitbucket.org/blog/a-modern-approach-to-change-management-with- bitbucket-and-jira-service-management

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events