-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (40 loc) · 954 Bytes
/
main.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
41
42
43
44
45
46
47
48
package main
import (
"context"
"fmt"
"os"
"github.com/buildkite/agent/v3/jobapi"
"github.com/kr/pretty"
)
func main() {
c, err := jobapi.NewDefaultClient()
if err != nil {
fatal(fmt.Errorf("starting jobapi client: %w", err))
}
switch os.Args[1] {
case "environment":
fmt.Println("Adding environment variables MOUNTAIN=cotopaxi and OCEAN=pacific")
c.EnvUpdate(context.Background(), &jobapi.EnvUpdateRequest{
Env: map[string]*string{
"MOUNTAIN": pt("cotopaxi"),
"OCEAN": pt("pacific"),
},
})
case "post-command":
fmt.Println("Removing environment variable OCEAN")
deleted, err := c.EnvDelete(context.Background(), []string{"OCEAN"})
if err != nil {
fatal(fmt.Errorf("deleting environment variable: %w", err))
}
pretty.Printf("Deleted: %v\n", deleted)
default:
panic("unknown command")
}
}
func pt(s string) *string {
return &s
}
func fatal(err error) {
fmt.Println(err.Error())
os.Exit(1)
}