Skip to content

Improve SCM info in build scans #45264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2019
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be boolean, no need for def?


// 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be String, no need for def?

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'
}
}