Skip to content

Commit c91c1e4

Browse files
committed
Improve SCM info in build scans (#45264)
1 parent 624b1f4 commit c91c1e4

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

gradle/build-scan.gradle

+19-13
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,32 @@ buildScan {
1818
value 'Jenkins Worker Label', it
1919
}
2020

21+
def isPrBuild = System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') != null
22+
2123
// 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) {
24+
if (System.getenv('GIT_COMMIT') && !isPrBuild) {
2325
background {
2426
def changes = "git diff --name-only ${System.getenv('GIT_PREVIOUS_COMMIT')}..${System.getenv('GIT_COMMIT')}".execute().text.trim()
2527
value 'Git Changes', changes
2628
}
2729
}
28-
} else {
29-
tag 'LOCAL'
30-
}
3130

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
31+
// Add SCM information
32+
if (isPrBuild) {
33+
value 'Git Commit ID', System.getenv('ghprbActualCommit')
34+
value 'Git Branch', System.getenv('ghprbTargetBranch')
35+
tag System.getenv('ghprbTargetBranch')
36+
tag "pr/${System.getenv('ghprbPullId')}"
37+
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('ghprbActualCommit')}"
38+
link 'Pull Request', System.getenv('ghprbPullLink')
39+
} else {
40+
def branch = System.getenv('GIT_BRANCH').split('/').last()
41+
value 'Git Commit ID', System.getenv('GIT_COMMIT')
42+
value 'Git Branch', branch
43+
tag branch
44+
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('GIT_COMMIT')}"
4045
}
41-
link 'Source', "https://github.com/elastic/elasticsearch/commit/${scmInfo.change}"
46+
} else {
47+
tag 'LOCAL'
4248
}
4349
}

0 commit comments

Comments
 (0)