Cloud Build Notifier is a tool that sends alerts when the state of a Google Cloud Build job changes.
To use this app, make sure you have Cargo installed.
This app honors GOOGLE_APPLICATION_CREDENTIALS
, if that is not set, it attempts to auth using the Application Default Credentials, if that is not found it attempts to auth with the google metadata server.
Before using Cloud Build Notifier, you need to configure it by following these steps:
- Create a Cloud Pub/Sub topic on Google Cloud Platform:
gcloud pubsub topics create cloud-builds
- Create a subscription for the topic
gcloud pubsub subscriptions create subscriber-id \
--topic=cloud-builds
To receive notifications on Slack, you'll need to configure the Slack integration in your app's YAML configuration file. Here's an example:
output:
type: slack
params:
webhook: https://hooks.slack.com/services/YYYYYYYYY/XXXXXXXXXXXXXXXXXXXXXXXXXX
secret_manager: projects/1234567890/secrets/MY_SECRET/versions/latest
Slack requires a webhook URL. You can provide it directly with the webhook key or use the secret_manager key to fetch the webhook from Google Cloud Platform. Only one of these two parameters is required.
To disable notifications
output:
type: null
params: {}
You can use this in the triggers.custom[]
section to disable notifications for specific triggers.
This is using the Rust Tera template language
There are 3 keys within the template context that can be used for rendering within the template.
The event
key within the template is the full event that is published to Pub/Sub.
{
"id": "1234-5678-909876-5443-2100",
"status": "SUCCESS",
...
}
To access the status field within the template, It can be done like this:
{{ event.status }}
buildTime
- This key is derived from the event start and finish times. It is the total time the build took to run. The format is {}h {}m {}s
. You can access this from the template with:
{{ buildTime }}
This process downloads the logs from the cloud build run and loads it into the log
key within the template context.
{{ log }}
Follow these steps to build and run Cloud Build Notifier locally:
Build
cargo build
Run
cargo run -- -c /path/to/config.yaml
You can also build and run Cloud Build Notifier using Docker. Here's how:
Build
docker build -t cloud-build-notifier:latest . --target app