Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

jgarber623/google-cloud-build-slack-webhook

Repository files navigation

google-cloud-build-slack-webhook

Send Google Cloud Build notifications to Slack using Google Cloud Functions.

Screenshot of a Slack channel displaying Google Cloud Build notifications

Getting Started

Before using google-cloud-build-slack-webhook, you'll need to have a few things squared away:

  1. a Google Cloud account,
  2. an application built with Google Cloud Build,
  3. a Slack workspace (with permissions to create Incoming Webhooks),
  4. the Google Cloud SDK installed on your cmoputer,
  5. Node.js installed on your computer, and
  6. comfort with the command line.

Note: For this walkthrough, we'll use indieweb-endpoints-cc as the Google Cloud project ID. You'll want to substitute that value with your own project's ID.

Installation and Configuration

With Node.js installed, clone this repository and run npm install to install the project's dependencies.

Note: Give the Google Cloud Build documentation article Configuring notifications for third-party services a read. It's a solid rundown of the steps necessary to set up notifications to Slack using webhooks. The following are a few customized steps for deploying google-cloud-build-slack-webhook.

First, follow the steps outlined in the documentation linked above to create a new Incoming Webhook in your Slack workspace. With the webhook's URL, create a .env file in the root of this project:

cp .env{.sample,}

Populate the .env file with your project's GitHub repository URL and your newly-created Slack webhook URL:

GITHUB_REPO_URL=https://github.com/jgarber623/indieweb-endpoints.cc
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/xxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxx

Using the Google Cloud SDK, set the current project:

gcloud config set project indieweb-endpoints-cc

Next, export a unique BUCKET_NAME variable. This will be used when creating and interacting with a bucket on Google Cloud Storage. Bucket names must be globally unique (thus the date | md5 | cut -c -10 bits borrowed from Philippe Modard's setup.sh script).

export BUCKET_NAME=$(gcloud config get-value project)_cloudbuild_webhook_$(date | md5 | cut -c -10)

Note: You'll want to keep this bucket name handy for future command line sessions. Keep it somewhere safe!

Use gsutil to create the bucket on Google Cloud Storage:

gsutil mb gs://$BUCKET_NAME

You should now be able to deploy to Google Cloud Functions:

npm run deploy

If all goes well, you'll now receive notifications of Slack when Google Cloud Build runs on your project!

Acknowledgments

The following documentation and projects served as guides and inspiration for the development of google-cloud-build-slack-webhook:

google-cloud-build-slack-webhook is written and maintained by Jason Garber.

License

google-cloud-build-slack-webhook is freely available under the MIT License. Use it, learn from it, fork it, improve it, change it, tailor it to your needs.