Features:
- send slack notifications about successful and failed builds;
- link to build details in slack message;
- no need in additional step in cloudbuild.yaml;
- report success and failure statuses;
- show trigger information in slack message;
- customize slack message using substitution in cloudbuild.yaml.
Prerequisites:
- Google Cloud Platform project with enabled Cloud Functions API;
- gcloud command-line util authorized to deploy cloud functions;
- Slack webhook url.
Deployment:
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR_TOKENS ./deploy.sh
This script will deploy cloud function gcbSubscribeSlack
triggered by cloud-build
PubSub topic.
Message content can be (optionally) defined by _SLACK_MESSAGE_TEMPLATE
substitution in cloudbuild.yaml. Value should be a valid ejs template:
steps:
# ... build steps ...
substitutions:
_SLACK_MESSAGE_TEMPLATE: '<%= emoji %> *https://<%= build.substitutions._OVERLAY %>.example.com* frontend build & deploy `<%= build.id %>` <%= build.status %>'
emoji
corresponds to a build status, build
is object containing build information, it's structure is defined here.
The default message template is <%= emoji %> `<%= build.id %>` <%= build.status %>