slackbot

command module
v0.0.0-...-eb8cdb2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

slackbot

Slackbot allows you to post build status messages to Slack.

Slack screenshot

Getting started

If you are new to Google Cloud Build, we recommend you start by visiting the manage resources page in the Cloud Console, enable billing, enable the Cloud Build API, and install the Cloud SDK.

Clone this repository and build the builder:

gcloud builds submit . --config=cloudbuild.yaml

Follow instructions on the Slack website to create a bot for your workspace. Copy and paste the webhook URL, you'll need it in a moment. If you want a neat bot profile image, you can download and use the official Cloud Build solution icon. (Note Slack will ask you to resize it to 500 x 500 pixels first.)

Using this tool

Add the builder as the first step in your project's cloudbuild.yaml: this triggers an independent "watcher" build which posts a status update whenever your main build completes - whether it's success or failure.

steps:
- name: 'gcr.io/$PROJECT_ID/slackbot'
  args: [ '--build', '$BUILD_ID',
          '--webhook', '<Add your webhook URL here>' ]
...

API

build

type string

description ID of monitored build

notes Required

example

steps:
- name: gcr.io/$PROJECT_ID/slackbot
  args:
  # ...
  - --build
  - 333225b1-b215-4992-9241-d8f4f3197be2
  # ...
webhook

type string

description Slack webhook URL

notes Required

example

steps:
- name: gcr.io/$PROJECT_ID/slackbot
  args:
  # ...
  - --webhook
  - https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
  # ...
mode

type string

default "trigger"

description Mode the builder runs in

notes Required. Must be one of: "trigger", "monitor"

example

steps:
- name: gcr.io/$PROJECT_ID/slackbot
  args:
  # ...
  - --mode
  - trigger
  # ...
copy-name

type bool

default false

description Copy name of slackbot's build step from monitored build to watcher build

notes If enabled, the name of the slackbot build step name must include "slackbot". If not enabled, watcher build will use name: gcr.io/$PROJECT_ID/slackbot.

example

steps:
- name: gcr.io/$PROJECT_ID/slackbot@sha256:5ae97d5e41e8c4c87f30b3766184e4440c7e4092ccebf13a166ee09ecf9891f5
  args:
  # ...
  - --copy-name
  # ...
copy-tags

type bool

default false

description Copy tags from monitored build to watcher build

notes If disabled, the watcher build will use tags: ["slackbot"]. If enabled, the monitored build's tags will be added to the defaults. In the following example, the resulting values for the watcher build would be tags: ["slackbot", "e2e"].

example

steps:
- name: gcr.io/$PROJECT_ID/slackbot
  args:
  # ...
  - --copy-tags
  # ...

tags:
- e2e
copy-timeout

type bool

default false

description Copy timeout from monitored build to watcher build

notes If enabled, watcher build's timeout will be set to monitored build's timeout (plus a small margin for transient API errors encountered by the watcher). If disabled, watcher build's timeout will not be set (i.e., Cloud Build's defaults will apply).

example

steps:
- name: gcr.io/$PROJECT_ID/slackbot
  args:
  # ...
  - --copy-timeout
  # ...

timeout: 900s

Examples

Examples showing both successful and unsuccessful builds are in the examples directory.

Customization

You may wish to customize your build notifications and provide different information in the messages posted to Slack. To do this, edit the JSON payload in notify.go, following the Slack message formatting guidelines.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL