Slackbot allows you to post build status messages to Slack.
If you are new to Google Cloud Build, we recommend you start by visiting the manage resources page in the Cloud Console, enable billing, enable the Cloud Build API, and install the Cloud SDK.
Clone this repository and build the builder:
gcloud builds submit . --config=cloudbuild.yaml
Follow instructions on the Slack website to create a bot for your workspace. Copy and paste the webhook URL, you'll need it in a moment. If you want a neat bot profile image, you can download and use the official Cloud Build solution icon. (Note Slack will ask you to resize it to 500 x 500 pixels first.)
Add the builder as the first step in your project's cloudbuild.yaml
: this triggers an independent "watcher" build which posts a status update whenever your main build completes - whether it's success or failure.
steps:
- name: 'gcr.io/$PROJECT_ID/slackbot'
args: [ '--build', '$BUILD_ID',
'--webhook', '<Add your webhook URL here>' ]
...
type string
description ID of monitored build
notes Required
example
steps:
- name: gcr.io/$PROJECT_ID/slackbot
args:
# ...
- --build
- 333225b1-b215-4992-9241-d8f4f3197be2
# ...
type string
description Slack webhook URL
notes Required
example
steps:
- name: gcr.io/$PROJECT_ID/slackbot
args:
# ...
- --webhook
- https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
# ...
type string
default "trigger"
description Mode the builder runs in
notes Required. Must be one of: "trigger"
, "monitor"
example
steps:
- name: gcr.io/$PROJECT_ID/slackbot
args:
# ...
- --mode
- trigger
# ...
type bool
default false
description Copy name
of slackbot's build step from monitored build to watcher build
notes If enabled, the name
of the slackbot build step name must include "slackbot"
. If not enabled, watcher build will use name: gcr.io/$PROJECT_ID/slackbot
.
example
steps:
- name: gcr.io/$PROJECT_ID/slackbot@sha256:5ae97d5e41e8c4c87f30b3766184e4440c7e4092ccebf13a166ee09ecf9891f5
args:
# ...
- --copy-name
# ...
type bool
default false
description Copy tags
from monitored build to watcher build
notes If disabled, the watcher build will use tags: ["slackbot"]
. If enabled, the monitored build's tags will be added to the defaults. In the following example, the resulting values for the watcher build would be tags: ["slackbot", "e2e"]
.
example
steps:
- name: gcr.io/$PROJECT_ID/slackbot
args:
# ...
- --copy-tags
# ...
tags:
- e2e
type bool
default false
description Copy timeout
from monitored build to watcher build
notes If enabled, watcher build's timeout
will be set to monitored build's timeout
(plus a small margin for transient API errors encountered by the watcher). If disabled, watcher build's timeout
will not be set (i.e., Cloud Build's defaults will apply).
example
steps:
- name: gcr.io/$PROJECT_ID/slackbot
args:
# ...
- --copy-timeout
# ...
timeout: 900s
Examples showing both successful and unsuccessful builds are in the examples directory.
You may wish to customize your build notifications and provide different information in the messages posted to Slack. To do this, edit the JSON payload in notify.go, following the Slack message formatting guidelines.