Spring Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.7 KiB

tagOs()
tagIde()
tagCiOrLocal()
addCiMetadata()
addGitMetadata()
void tagOs() {
buildScan.tag System.getProperty('os.name')
}
void tagIde() {
if (System.getProperty('idea.version')) {
buildScan.tag 'IntelliJ IDEA'
} else if (System.getProperty('eclipse.buildId')) {
buildScan.tag 'Eclipse'
}
}
void tagCiOrLocal() {
buildScan.tag(isCi() ? 'CI' : 'LOCAL')
}
void addGitMetadata() {
buildScan.background {
def gitCommitId = execAndGetStdout('git', 'rev-parse', '--short=8', '--verify', 'HEAD')
def gitBranchName = execAndGetStdout('git', 'rev-parse', '--abbrev-ref', 'HEAD')
def gitStatus = execAndGetStdout('git', 'status', '--porcelain')
if(gitCommitId) {
def commitIdLabel = 'Git Commit ID'
value commitIdLabel, gitCommitId
link 'Git commit build scans', customValueSearchUrl([(commitIdLabel): gitCommitId])
}
if (gitBranchName) {
tag gitBranchName
value 'Git branch', gitBranchName
}
if (gitStatus) {
tag 'dirty'
value 'Git status', gitStatus
}
}
}
void addCiMetadata() {
def ciBuild = 'CI BUILD'
if (System.getenv('bamboo.resultsUrl')) {
buildScan.link ciBuild, System.getenv('bamboo.resultsUrl')
}
}
boolean isCi() {
System.getenv('bamboo.resultsUrl')
}
String execAndGetStdout(String... args) {
def stdout = new ByteArrayOutputStream()
exec {
commandLine(args)
standardOutput = stdout
}
return stdout.toString().trim()
}
String customValueSearchUrl(Map<String, String> search) {
def query = search.collect { name, value ->
"search.names=${encodeURL(name)}&search.values=${encodeURL(value)}"
}.join('&')
"$buildScan.server/scans?$query"
}
String encodeURL(String url){
URLEncoder.encode(url, 'UTF-8')
}