1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/orchestrator/jenkins.go
Marc Bormeth b5357f9437
feat: Add environment information to orchestrator package (#2942)
* Fix Orchestrator detection

* Add unit tests

* Add environment info to orchestrator package
2021-06-25 10:50:56 +02:00

41 lines
851 B
Go

package orchestrator
import (
"os"
)
type JenkinsConfigProvider struct{}
func (j *JenkinsConfigProvider) GetBranch() string {
return os.Getenv("GIT_BRANCH")
}
func (j *JenkinsConfigProvider) GetBuildUrl() string {
return os.Getenv("BUILD_URL")
}
func (j *JenkinsConfigProvider) GetCommit() string {
return os.Getenv("GIT_COMMIT")
}
func (j *JenkinsConfigProvider) GetRepoUrl() string {
return os.Getenv("GIT_URL")
}
func (j *JenkinsConfigProvider) GetPullRequestConfig() PullRequestConfig {
return PullRequestConfig{
Branch: os.Getenv("CHANGE_BRANCH"),
Base: os.Getenv("CHANGE_TARGET"),
Key: os.Getenv("CHANGE_ID"),
}
}
func (j *JenkinsConfigProvider) IsPullRequest() bool {
return truthy("CHANGE_ID")
}
func isJenkins() bool {
envVars := []string{"JENKINS_HOME", "JENKINS_URL"}
return areIndicatingEnvVarsSet(envVars)
}