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/azureDevOps.go

53 lines
1.6 KiB
Go
Raw Normal View History

package orchestrator
import (
"os"
"strings"
)
type AzureDevOpsConfigProvider struct{}
func (a *AzureDevOpsConfigProvider) GetBranch() string {
tmp := os.Getenv("BUILD_SOURCEBRANCH")
return strings.TrimPrefix(tmp, "refs/heads/")
}
func (a *AzureDevOpsConfigProvider) GetBuildUrl() string {
return os.Getenv("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI") + os.Getenv("SYSTEM_TEAMPROJECT") + "/_build/results?buildId=" + os.Getenv("BUILD_BUILDID")
}
func (a *AzureDevOpsConfigProvider) GetCommit() string {
return os.Getenv("BUILD_SOURCEVERSION")
}
func (a *AzureDevOpsConfigProvider) GetRepoUrl() string {
return os.Getenv("BUILD_REPOSITORY_URI")
}
func (a *AzureDevOpsConfigProvider) GetPullRequestConfig() PullRequestConfig {
prKey := os.Getenv("SYSTEM_PULLREQUEST_PULLREQUESTID")
// This variable is populated for pull requests which have a different pull request ID and pull request number.
// In this case the pull request ID will contain an internal numeric ID and the pull request number will be provided
// as part of the 'SYSTEM_PULLREQUEST_PULLREQUESTNUMBER' environment variable.
prNumber, prNumberEnvVarSet := os.LookupEnv("SYSTEM_PULLREQUEST_PULLREQUESTNUMBER")
if prNumberEnvVarSet == true {
prKey = prNumber
}
return PullRequestConfig{
Branch: os.Getenv("SYSTEM_PULLREQUEST_SOURCEBRANCH"),
Base: os.Getenv("SYSTEM_PULLREQUEST_TARGETBRANCH"),
Key: prKey,
}
}
func (a *AzureDevOpsConfigProvider) IsPullRequest() bool {
return os.Getenv("BUILD_REASON") == "PullRequest"
}
func isAzure() bool {
envVars := []string{"AZURE_HTTP_USER_AGENT"}
return areIndicatingEnvVarsSet(envVars)
}