Skip to content

Cloud Build Notifier is a tool that sends alerts when the state of a Google Cloud Build job changes.

Notifications You must be signed in to change notification settings

rpfernandezjr/cloud-build-notifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cloud-build-notifier

Cloud Build Notifier is a tool that sends alerts when the state of a Google Cloud Build job changes.

Installation

To use this app, make sure you have Cargo installed.

GCP Auth

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.

Configuration

Before using Cloud Build Notifier, you need to configure it by following these steps:

  1. Create a Cloud Pub/Sub topic on Google Cloud Platform:
gcloud pubsub topics create cloud-builds
  1. Create a subscription for the topic
gcloud pubsub subscriptions create subscriber-id \
   --topic=cloud-builds

Notification Types

Slack Integration

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.

Disable a Notification

To disable notifications

output:
  type: null
  params: {}

You can use this in the triggers.custom[] section to disable notifications for specific triggers.

Templates

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.

Event

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

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 }}

log

This process downloads the logs from the cloud build run and loads it into the log key within the template context.

{{ log }}

Local Development

Follow these steps to build and run Cloud Build Notifier locally:

Build

cargo build

Run

cargo run -- -c /path/to/config.yaml

Docker

You can also build and run Cloud Build Notifier using Docker. Here's how:

Build

docker build -t cloud-build-notifier:latest . --target app

About

Cloud Build Notifier is a tool that sends alerts when the state of a Google Cloud Build job changes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published