2019-08-14 16:16:20 -04:00
|
|
|
import org.elasticsearch.gradle.OS
|
2020-02-18 19:24:06 -05:00
|
|
|
import org.elasticsearch.gradle.info.BuildParams
|
2019-11-11 04:22:47 -05:00
|
|
|
import org.gradle.initialization.BuildRequestMetaData
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
|
2020-01-10 17:51:25 -05:00
|
|
|
long startTime = project.gradle.services.get(BuildRequestMetaData).getStartTime()
|
2019-07-16 12:34:00 -04:00
|
|
|
|
|
|
|
buildScan {
|
2019-11-14 06:01:23 -05:00
|
|
|
URL jenkinsUrl = System.getenv('JENKINS_URL') ? new URL(System.getenv('JENKINS_URL')) : null
|
|
|
|
String buildNumber = System.getenv('BUILD_NUMBER')
|
|
|
|
String buildUrl = System.getenv('BUILD_URL')
|
|
|
|
String jobName = System.getenv('JOB_NAME')
|
|
|
|
String nodeName = System.getenv('NODE_NAME')
|
2019-07-16 12:34:00 -04:00
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
tag OS.current().name()
|
2019-08-14 16:16:20 -04:00
|
|
|
|
2020-01-10 17:51:25 -05:00
|
|
|
// Automatically publish scans from Elasticsearch CI
|
2019-11-14 06:01:23 -05:00
|
|
|
if (jenkinsUrl?.host?.endsWith('elastic.co')) {
|
|
|
|
publishAlways()
|
|
|
|
buildScan.server = 'https://gradle-enterprise.elastic.co'
|
|
|
|
}
|
2019-07-16 12:34:00 -04:00
|
|
|
|
2020-01-10 17:51:25 -05:00
|
|
|
// Link to Jenkins worker logs and system metrics
|
2019-11-14 06:01:23 -05:00
|
|
|
if (nodeName) {
|
|
|
|
link 'System logs', "https://infra-stats.elastic.co/app/infra#/logs?" +
|
|
|
|
"&logFilter=(expression:'host.name:${nodeName}',kind:kuery)"
|
|
|
|
buildFinished {
|
|
|
|
link 'System metrics', "https://infra-stats.elastic.co/app/infra#/metrics/host/" +
|
|
|
|
"${nodeName}?_g=()&metricTime=(autoReload:!f,refreshInterval:5000," +
|
|
|
|
"time:(from:${startTime - TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES)},interval:%3E%3D1m," +
|
|
|
|
"to:${System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES)}))"
|
2019-11-11 04:22:47 -05:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
2019-11-11 04:22:47 -05:00
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
// Jenkins-specific build scan metadata
|
|
|
|
if (jenkinsUrl) {
|
2020-01-10 17:51:25 -05:00
|
|
|
// Parse job name in the case of matrix builds
|
|
|
|
// Matrix job names come in the form of "base-job-name/matrix_param1=value1,matrix_param2=value2"
|
|
|
|
def splitJobName = jobName.split('/')
|
2020-01-21 18:16:29 -05:00
|
|
|
if (splitJobName.length > 1 && splitJobName.last() ==~ /^([a-zA-Z0-9_\-]+=[a-zA-Z0-9_\-&\.]+,?)+$/) {
|
2020-01-13 12:31:39 -05:00
|
|
|
def baseJobName = splitJobName.dropRight(1).join('/')
|
|
|
|
tag baseJobName
|
2020-01-14 12:53:46 -05:00
|
|
|
tag splitJobName.last()
|
2020-01-13 12:31:39 -05:00
|
|
|
value 'Job Name', baseJobName
|
|
|
|
def matrixParams = splitJobName.last().split(',')
|
2020-01-10 17:51:25 -05:00
|
|
|
matrixParams.collect { it.split('=') }.each { param ->
|
|
|
|
value "MATRIX_${param[0].toUpperCase()}", param[1]
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tag jobName
|
|
|
|
value 'Job Name', jobName
|
|
|
|
}
|
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
tag 'CI'
|
|
|
|
link 'Jenkins Build', buildUrl
|
|
|
|
link 'GCP Upload', "https://console.cloud.google.com/storage/elasticsearch-ci-artifacts/jobs/${jobName}/build/${buildNumber}.tar.bz2"
|
2020-01-10 17:51:25 -05:00
|
|
|
value 'Job Number', buildNumber
|
2019-11-11 04:22:47 -05:00
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
System.getenv().getOrDefault('NODE_LABELS', '').split(' ').each {
|
|
|
|
value 'Jenkins Worker Label', it
|
|
|
|
}
|
2019-07-16 12:34:00 -04:00
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
// Add SCM information
|
|
|
|
def isPrBuild = System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') != null
|
|
|
|
if (isPrBuild) {
|
|
|
|
value 'Git Commit ID', System.getenv('ghprbActualCommit')
|
|
|
|
value 'Git Branch', System.getenv('ghprbTargetBranch')
|
|
|
|
tag System.getenv('ghprbTargetBranch')
|
|
|
|
tag "pr/${System.getenv('ghprbPullId')}"
|
|
|
|
tag 'pull-request'
|
|
|
|
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('ghprbActualCommit')}"
|
|
|
|
link 'Pull Request', System.getenv('ghprbPullLink')
|
2019-08-07 12:04:20 -04:00
|
|
|
} else {
|
2019-11-14 06:01:23 -05:00
|
|
|
if (System.getenv('GIT_BRANCH')) {
|
|
|
|
def branch = System.getenv('GIT_BRANCH').split('/').last()
|
|
|
|
value 'Git Branch', branch
|
|
|
|
tag branch
|
|
|
|
}
|
2020-02-18 19:24:06 -05:00
|
|
|
value 'Git Commit ID', BuildParams.gitRevision
|
|
|
|
link 'Source', "https://github.com/elastic/elasticsearch/tree/${BuildParams.gitRevision}"
|
2019-07-16 12:34:00 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
} else {
|
|
|
|
tag 'LOCAL'
|
|
|
|
}
|
2019-10-04 01:41:06 -04:00
|
|
|
}
|