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?
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@chare Yes that dialog, unfortunately there is no differentiation between the type of a pipeline possible, e.g. only failed custom pipelines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think it does work, it's just then it's for all failed Pipelines which might be too much for specific messaging.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.