/
env.go
53 lines (44 loc) · 1.37 KB
/
env.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
49
50
51
52
53
package env
import (
"fmt"
"os"
)
func notFoundErr(varname string) error {
return fmt.Errorf("env variable %q not set", varname)
}
func get(varname string) string {
return os.Getenv(varname)
}
func mustGet(varname string) (string, error) {
val := get(varname)
if val == "" {
return "", notFoundErr(varname)
}
return val, nil
}
// EvgIsPatch returns whether the current evergreen task is a patch,
// based on the value of an env variable set by the evg project file.
func EvgIsPatch() bool {
return get("EVG_IS_PATCH") != ""
}
// EvgIsTagTriggered returns whether the current evergreen task is
// part of a tag-triggered version, based on the value of an env
// variable set by the evg project file.
func EvgIsTagTriggered() bool {
return get("EVG_TRIGGERED_BY_TAG") != ""
}
// EvgBuildID returns the build_id of the current evergreen task,
// based on the value of an env variable set by the evg project file.
func EvgBuildID() (string, error) {
return mustGet("EVG_BUILD_ID")
}
// EvgVariant returns the variant name for the current evergreen task,
// based on the value of an env variable set by the evg project file.
func EvgVariant() (string, error) {
return mustGet("EVG_VARIANT")
}
// EvgVersionID returns the current evergreen version,
// based on the value of an env variable set by the evg project file.
func EvgVersionID() (string, error) {
return mustGet("EVG_VERSION")
}