Skip to content

Slack integration for Google Cloud Container Builder, using Google Cloud Functions

License

Notifications You must be signed in to change notification settings

Philmod/google-cloud-build-slack

Repository files navigation

google-cloud-build-slack

Slack integration for Google Cloud Build, using Google Cloud Functions to post messages to Slack when a build reaches a specific state.

Setup

  1. Create a Slack app, and copy the webhook URL:
export SLACK_WEBHOOK_URL=my-slack-webhook-url
  1. Set the PROJECT_ID variable:
export PROJECT_ID=my-project-id
  1. [Optionally] Set a github token to obtain github commit author info in slack messages if applicable. Please refer to the current limitations.
export GITHUB_TOKEN=my-token
  1. [Optionally] Set the status you want a message for, here are the default ones:
export GC_SLACK_STATUS="SUCCESS FAILURE TIMEOUT INTERNAL_ERROR"
  1. Create the function with setup.sh (Option 1) OR serverless framework (Option 2)

Option 1: Deploy with script

  • [Optionally] Set a specific BUCKET_NAME and a FUNCTION_NAME.
  • Create the function:
. ./setup.sh
# OR
npm run setup

Option 2: Deploy with serverless framework

  1. Install serverless
npm install serverless -g
  1. Ensure that the value of project.credentials in serverless.yml points to credentials with appropriate roles Serverless can use to create resources in your Project.

  2. Deploy

serverless deploy

Teardown

If deployed with script

The teardown script will delete the function FUNCTION_NAME, and the bucket BUCKET_NAME.

. ./teardown.sh
# OR
npm run teardown

If deployed with serverless framework

Remove

serverless remove

FAQ

How much does it cost?

Each build invokes 3 times the function:

  • when the build is queued
  • when the build starts
  • when the build reaches a final status.

Here is the GCF pricing for calculation.

Can I use an existing bucket?

Yes if deploying with the setup script, specify the BUCKET_NAME:

exports BUCKET_NAME=my-bucket

If deploying with the serverless framework however, this option is not yet available in the Google Cloud Functions provider plugin, but hopefully will be in the near future as an issue has been opened.

How can I update a function?

If you use the setup script with the same FUNCTION_NAME, it will update the existing function.

If you use serverless, simply re running serverless deploy will update the existing function.

Where can I find the SLACK_WEBHOOK_URL?

After creating an application on Slack, active the Incoming Webhooks. You'll find the url on that page: slack webhook

Why do I have to source the script?

In the case where a BUCKET_NAME is not defined, a random one is generated. And in order to delete it during the teardown, the variable has to be exported from the setup script.

What are the limitations of using github token to get github commit author info?

For github commit author info to be displayed, the cloud source repositories must be in the form of github_<OWNER>_<REPO> and there cannot be underscores in either <OWNER> or <REPO>. A possible solution to bypass this limitation would be to retrieve owner and repo info directly from GitHubEventsConfig.

About

Slack integration for Google Cloud Container Builder, using Google Cloud Functions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published