OpenSearch/gradle/build-scan.gradle
Alpar Torok cb9f45ad78 Always publish a build scan in CI (#48348)
* Always publish a build scan in CI

This PR changes the build scan configuration to alwasy publisha  build
scan when running in our CI.

We should alkready be passing these env vars into the Vagrant VM so this
will make it produce a build scan too.

The old properties to accept build scan ToS on the public server are
thus no longer relevant and will be cleaned up from the Jenkins config
once this is merged.

* Pass env vars to vagrant VM
* Enable running in parallel in the VM
* Add job name and build nomber as custom values
2019-10-23 13:27:56 +03:00

61 lines
2.3 KiB
Groovy

import org.elasticsearch.gradle.OS
buildScan {
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')
tag OS.current().name()
if (jobName) {
value 'Job name', jobName
}
if(buildNumber) {
value 'Job number', buildNumber
}
if (jenkinsUrl?.host?.endsWith('elastic.co')) {
publishAlways()
buildScan.server = 'https://gradle-enterprise.elastic.co'
}
// Jenkins-specific build scan metadata
if (jenkinsUrl) {
tag 'CI'
tag jobName
link 'Jenkins Build', buildUrl
link 'GCP Upload', "https://console.cloud.google.com/storage/elasticsearch-ci-artifacts/jobs/${jobName}/build/${buildNumber}.tar.bz2"
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')
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')
} else {
if (System.getenv('GIT_BRANCH')) {
def branch = System.getenv('GIT_BRANCH').split('/').last()
value 'Git Branch', branch
tag branch
}
if (System.getenv('GIT_COMMIT')) {
value 'Git Commit ID', System.getenv('GIT_COMMIT')
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('GIT_COMMIT')}"
background {
def changes = "git diff --name-only ${System.getenv('GIT_PREVIOUS_COMMIT')}..${System.getenv('GIT_COMMIT')}".execute().text.trim()
value 'Git Changes', changes
}
}
}
} else {
tag 'LOCAL'
}
}