-
Notifications
You must be signed in to change notification settings - Fork 25
/
automation_environment_provider.go
63 lines (54 loc) · 1.77 KB
/
automation_environment_provider.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
54
55
56
57
58
59
60
61
62
63
package api
import (
"fmt"
"strings"
)
var knownEnvironments = map[string][]string{
"Octopus": {"AgentProgramDirectoryPath"},
// https://confluence.jetbrains.com/display/TCD9/Predefined+Build+Parameters
"TeamCity": {"TEAMCITY_VERSION"},
// https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables
"GitHubActions": {"GITHUB_ACTIONS"},
// https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables
"AzureDevOps": {"TF_BUILD", "BUILD_BUILDID", "AGENT_WORKFOLDER"},
// https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html
"Bamboo": {"bamboo_agentId"},
"AppVeyor": {"APPVEYOR"},
"BitBucket": {"BITBUCKET_BUILD_NUMBER"},
"Jenkins": {"JENKINS_URL"},
"CircleCI": {"CIRCLECI"},
"GitLabCI": {"GITLAB_CI"},
"Travis": {"TRAVIS"},
"GoCD": {"GO_PIPELINE_LABEL"},
"BitRise": {"BITRISE_IO"},
"Buddy": {"BUDDY_WORKSPACE_ID"},
"BuildKite": {"BUILDKITE"},
"CirrusCI": {"CIRRUS_CI"},
"AWSCodeBuild": {"CODEBUILD_BUILD_ARN"},
"Codeship": {"CI_NAME"},
"Drone": {"DRONE"},
"Dsari": {"DSARI"},
"Hudson": {"HUDSON_URL"},
"MagnumCI": {"MAGNUM"},
"SailCI": {"SAILCI"},
"Semaphore": {"SEMAPHORE"},
"Shippable": {"SHIPPABLE"},
"SolanoCI": {"TDDIUM"},
"StriderCD": {"STRIDER"},
}
func GetAutomationEnvironment(e Environment) string {
var environment = "NoneOrUnknown"
for key, variables := range knownEnvironments {
for _, v := range variables {
if e.Getenv(v) != "" {
environment = key
}
}
}
if environment == "TeamCity" {
value := e.Getenv(knownEnvironments[environment][0])
parts := strings.Split(value, " ")
environment = fmt.Sprintf("%s/%s", environment, parts[0])
}
return environment
}