Skip to content

Commit

Permalink
Improve SCM info in build scans (#45264)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira committed Aug 7, 2019
1 parent 624b1f4 commit c91c1e4
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions gradle/build-scan.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,32 @@ buildScan {
value 'Jenkins Worker Label', it
}

def isPrBuild = System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') != null

// Capture changes included in this CI build except for pull request builds
if (System.getenv('GIT_COMMIT') && System.getenv('ROOT_BUILD_CAUSE_GHPRBCAUSE') == null) {
if (System.getenv('GIT_COMMIT') && !isPrBuild) {
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'
}

// Add SCM information
def scmInfo = project.extensions.findByType(ScmInfoExtension)
if (scmInfo && scmInfo.change && scmInfo.branch) {
value 'Git Commit ID', scmInfo.change
// Don't tag the branch if we are in a detached head state
if (scmInfo.branch ==~ /[0-9a-f]{5,40}/ == false) {
value 'Git Branch', scmInfo.branch
tag scmInfo.branch
// Add SCM information
if (isPrBuild) {
value 'Git Commit ID', System.getenv('ghprbActualCommit')
value 'Git Branch', System.getenv('ghprbTargetBranch')
tag System.getenv('ghprbTargetBranch')
tag "pr/${System.getenv('ghprbPullId')}"
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('ghprbActualCommit')}"
link 'Pull Request', System.getenv('ghprbPullLink')
} else {
def branch = System.getenv('GIT_BRANCH').split('/').last()
value 'Git Commit ID', System.getenv('GIT_COMMIT')
value 'Git Branch', branch
tag branch
link 'Source', "https://github.com/elastic/elasticsearch/tree/${System.getenv('GIT_COMMIT')}"
}
link 'Source', "https://github.com/elastic/elasticsearch/commit/${scmInfo.change}"
} else {
tag 'LOCAL'
}
}

0 comments on commit c91c1e4

Please sign in to comment.