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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is it possible to schedule a pipeline, and only have slack notifications if it fails?

I'm looking at replacing one of our jenkins pipelines with bitbucket. Currently, we have nightly builds, however these require someone to go and manually check whether they've been successful.

I would like the new scheduled pipeline to do a nightly build, but only trigger an alert into a slack channel if it fails. Is this possible?

2 answers

You can also set the chat notifications for your repository after you integrate bitbucket into a slack channel.  This works great, and I get a pass/fail notice after every pipeline run in my slack channel.  

Check out https://confluence.atlassian.com/bitbucket/notifications-for-bitbucket-pipelines-857053284.html

But how to set this up especially for custom pipelines only (here: that have been triggered by the scheduler)? I didn't find that option and the original poster (OP) asked for that. Maybe you know more?

Open the repository

Open Repository Settings

Open Chat Notifications

- if you don't already have a subscription configured, then you need to do that first

Configure the notifications you want, like "pipeline failed"Screen Shot 2020-06-08 at 11.00.57 AM.png

@chare Yes that dialog, unfortunately there is no differentiation between the type of a pipeline possible, e.g. only failed custom pipelines.

Yes - that is true.  does it not work for scheduled pipelines?  We don't use those, so I don't have any experience with them.

I think it does work, it's just then it's for all failed Pipelines which might be too much for specific messaging.

if it doesn't overload the messaging system, it might get annoying for the recipients ;-)

The Slack integration does not cover your specific case, so a solution does involve a slightly higher overhead, however curl and a slack bearer token should do it:

  • Create an after-script for your custom step pipeline.
  • If the BITBUCKET_EXIT_CODE environment variable is non-zero, the pipeline step failed
  • Fire the message with curl to Slack

After Script Example (Docs / Announcement Jan 2019)

image: node:10.15.0

pipelines:
custom: # Pipelines that are triggered manually
sonar: # The name that is displayed in the list in the Bitbucket Cloud GUI
- step:
script:
- echo "Manual triggers for Sonar are awesome!"
after-script:
- test $BITBUCKET_EXIT_CODE -ne 0 && curl ...

For larger command lines I often find YAML multiline strings useful for better readability.

Curl Example (from Slack docs)

curl -X POST -H 'Authorization: Bearer xoxb-1234-56789abcdefghijklmnop' \
-H 'Content-type: application/json' \
--data '{"channel":"C061EG9SL","text":"I hope the tour went well, Mr. Wonka.","attachments": [{"text":"Who wins the lifetime supply of chocolate?","fallback":"You could be telling the computer exactly what it can do with a lifetime supply of chocolate.","color":"#3AA3E3","attachment_type":"default","callback_id":"select_simple_1234","actions":[{"name":"winners_list","text":"Who should win?","type":"select","data_source":"users"}]}]}' \
https://slack.com/api/chat.postMessage

/Edit: There is a similar question regarding doing this, not with slack but email notifications which looks like another good reference:

 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

381 views 13 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you