-
Notifications
You must be signed in to change notification settings - Fork 849
/
trigger.go
40 lines (35 loc) · 837 Bytes
/
trigger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package slackbot
import (
"context"
"fmt"
"log"
cloudbuild "google.golang.org/api/cloudbuild/v1"
)
// Trigger starts an independent watcher build.
func Trigger(ctx context.Context, build string, webhook string) {
svc := gcbClient(ctx)
b := &cloudbuild.Build{
Steps: []*cloudbuild.BuildStep{
&cloudbuild.BuildStep{
Name: "gcr.io/$PROJECT_ID/slackbot",
Args: []string{
fmt.Sprintf("--build=%s", build),
fmt.Sprintf("--webhook=%s", webhook),
"--mode=monitor",
},
},
},
Tags: []string{"slackbot"},
}
project, err := getProject()
if err != nil {
log.Fatalf("Failed to get project: %v", err)
}
cr := svc.Projects.Builds.Create(project, b)
_, err = cr.Do()
if err != nil {
log.Fatalf("Failed to create watcher build: %v", err)
} else {
log.Printf("Triggered watcher build.")
}
}