Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ import java.time.LocalDateTime
develocity {

buildScan {
URL jenkinsUrl = System.getenv('JENKINS_URL') ? new URL(System.getenv('JENKINS_URL')) : null
String buildKiteUrl = System.getenv('BUILDKITE_BUILD_URL') ? System.getenv('BUILDKITE_BUILD_URL') : null

def onCI = System.getenv('CI') ? Boolean.parseBoolean(System.getenv('CI')) : false

// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
uploadInBackground = onCI == false

// Automatically publish scans from Elasticsearch CI
if (jenkinsUrl?.host?.endsWith('elastic.co') || jenkinsUrl?.host?.endsWith('elastic.dev') || System.getenv('BUILDKITE') == 'true') {
if (onCI) {
publishing.onlyIf { true }
server = 'https://gradle-enterprise.elastic.co'
} else if( server.isPresent() == false) {
Expand All @@ -38,73 +41,9 @@ develocity {
if (BuildParams.inFipsJvm) {
tag 'FIPS'
}

// Jenkins-specific build scan metadata
if (jenkinsUrl) {
// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
uploadInBackground = false

String buildNumber = System.getenv('BUILD_NUMBER')
String buildUrl = System.getenv('BUILD_URL')
String jobName = System.getenv('JOB_NAME')
String nodeName = System.getenv('NODE_NAME')
String jobBranch = System.getenv('ghprbTargetBranch') ?: System.getenv('JOB_BRANCH')

// Link to Jenkins worker logs and system metrics
if (nodeName) {
link 'System logs', "https://ci-stats.elastic.co/app/infra#/logs?&logFilter=(expression:'host.name:${nodeName}',kind:kuery)"
buildFinished {
link 'System metrics', "https://ci-stats.elastic.co/app/metrics/detail/host/${nodeName}"
}
}

// 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('/')
if (splitJobName.length > 1 && splitJobName.last() ==~ /^([a-zA-Z0-9_\-]+=[a-zA-Z0-9_\-&\.]+,?)+$/) {
def baseJobName = splitJobName.dropRight(1).join('/')
tag baseJobName
tag splitJobName.last()
value 'Job Name', baseJobName
def matrixParams = splitJobName.last().split(',')
matrixParams.collect { it.split('=') }.each { param ->
value "MATRIX_${param[0].toUpperCase()}", param[1]
}
} else {
tag jobName
value 'Job Name', jobName
}

tag 'CI'
link 'CI Build', buildUrl
link 'GCP Upload',
"https://console.cloud.google.com/storage/browser/_details/elasticsearch-ci-artifacts/jobs/${URLEncoder.encode(jobName, "UTF-8")}/build/${buildNumber}.tar.bz2"
value 'Job Number', buildNumber
if (jobBranch) {
tag jobBranch
value 'Git Branch', jobBranch
}

System.getenv().getOrDefault('NODE_LABELS', '').split(' ').each {
value 'Jenkins Worker Label', it
}

// Add SCM information
def isPrBuild = System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') != null
if (isPrBuild) {
value 'Git Commit ID', System.getenv('ghprbActualCommit')
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')
} else {
value 'Git Commit ID', BuildParams.gitRevision
link 'Source', "https://github.com/elastic/elasticsearch/tree/${BuildParams.gitRevision}"
}
} else if (buildKiteUrl) { //Buildkite-specific build scan metadata
// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
uploadInBackground = false

println "onCI = $onCI"
if (onCI) { //Buildkite-specific build scan metadata
String buildKiteUrl = System.getenv('BUILDKITE_BUILD_URL')
def branch = System.getenv('BUILDKITE_PULL_REQUEST_BASE_BRANCH') ?: System.getenv('BUILDKITE_BRANCH')
def repoMatcher = System.getenv('BUILDKITE_REPO') =~ /(https:\/\/github\.com\/|git@github\.com:)(\S+)\.git/
def repository = repoMatcher.matches() ? repoMatcher.group(2) : "<unknown>"
Expand Down