Skip to content

Commit e0e60b1

Browse files
committed
Improve build scan metadata (elastic#44247)
(cherry picked from commit 2797b24)
1 parent 3b5358f commit e0e60b1

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

build.gradle

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,13 @@ import org.gradle.util.DistributionLocator
2929
import org.gradle.plugins.ide.eclipse.model.SourceFolder
3030

3131
plugins {
32-
id 'com.gradle.build-scan' version '2.2.1'
32+
id 'com.gradle.build-scan' version '2.3'
3333
id 'base'
3434
id 'elasticsearch.global-build-info'
3535
}
36-
if (properties.get("org.elasticsearch.acceptScanTOS", "false") == "true") {
37-
buildScan {
38-
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
39-
termsOfServiceAgree = 'yes'
40-
}
41-
}
36+
37+
apply plugin: 'nebula.info-scm'
38+
apply from: 'gradle/build-scan.gradle'
4239

4340
// common maven publishing configuration
4441
allprojects {
@@ -49,7 +46,6 @@ allprojects {
4946

5047
BuildPlugin.configureRepositories(project)
5148

52-
apply plugin: 'nebula.info-scm'
5349
String licenseCommit
5450
if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
5551
licenseCommit = scminfo.change ?: "master" // leniency for non git builds

gradle/build-scan.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import nebula.plugin.info.scm.ScmInfoExtension
2+
3+
buildScan {
4+
def jenkinsUrl = System.getenv('JENKINS_URL') ? new URL(System.getenv('JENKINS_URL')) : null
5+
6+
// Accept Gradle ToS when project property org.elasticsearch.acceptScanTOS=true or this is an Elastic CI build
7+
if (jenkinsUrl?.host?.endsWith('elastic.co') || Boolean.valueOf(project.findProperty('org.elasticsearch.acceptScanTOS') ?: "false")) {
8+
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
9+
termsOfServiceAgree = 'yes'
10+
}
11+
12+
// Jenkins-specific build scan metadata
13+
if (jenkinsUrl) {
14+
tag 'CI'
15+
tag System.getenv('JOB_NAME')
16+
link 'Jenkins Build', System.getenv('BUILD_URL')
17+
System.getenv('NODE_LABELS').split(' ').each {
18+
value 'Jenkins Worker Label', it
19+
}
20+
21+
// Capture changes included in this CI build except for pull request builds
22+
if (System.getenv('GIT_COMMIT') && System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') == null) {
23+
background {
24+
def changes = "git diff --name-only ${System.getenv('GIT_PREVIOUS_COMMIT')}..${System.getenv('GIT_COMMIT')}".execute().text.trim()
25+
value 'Git Changes', changes
26+
}
27+
}
28+
} else {
29+
tag 'LOCAL'
30+
}
31+
32+
// Add SCM information
33+
def scmInfo = project.extensions.findByType(ScmInfoExtension)
34+
if (scmInfo && scmInfo.change && scmInfo.branch) {
35+
value 'Git Commit ID', scmInfo.change
36+
// Don't tag the branch if we are in a detached head state
37+
if (scmInfo.branch ==~ /[0-9a-f]{5,40}/ == false) {
38+
value 'Git Branch', scmInfo.branch
39+
tag scmInfo.branch
40+
}
41+
link 'Source', "https://github.com/elastic/elasticsearch/commit/${scmInfo.change}"
42+
}
43+
}

0 commit comments

Comments
 (0)