Skip to content

Commit

Permalink
Include branch information in build scans for buildkite jobs (elastic…
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira committed Oct 24, 2023
1 parent 00c2dae commit 32df495
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ buildScan {
// Disable async upload in CI to ensure scan upload completes before CI agent is terminated
uploadInBackground = false

def branch = System.getenv('BUILDKITE_BRANCH')
def branch = System.getenv('BUILDKITE_PULL_REQUEST_BASE_BRANCH') ?: System.getenv('BUILDKITE_BRANCH')
def repoMatcher = System.getenv('BUILDKITE_REPO') =~ /(https:\/\/github\.com\/|git@github\.com:)(\S+)\.git/
def repository = repoMatcher.matches() ? repoMatcher.group(2) : "<unknown>"
def jobName = (System.getenv('BUILDKITE_LABEL') ?: '').replaceAll(/[^a-zA-Z0-9_\-]+/, '_').toLowerCase()
def jobName = (System.getenv('BUILDKITE_LABEL') ?: '').replaceAll(/[^a-zA-Z0-9_\-]+/, ' ').trim().replaceAll(' ', '_').toLowerCase()

tag 'CI'
link 'CI Build', buildKiteUrl
Expand All @@ -110,6 +110,11 @@ buildScan {
value 'Job Name', jobName
tag jobName

if (branch) {
tag branch
value 'Git Branch', branch
}

// Add SCM information
def prId = System.getenv('BUILDKITE_PULL_REQUEST')
if (prId != 'false') {
Expand All @@ -122,7 +127,6 @@ buildScan {
} else {
value 'Git Commit ID', BuildParams.gitRevision
link 'Source', "https://github.com/${repository}/tree/${BuildParams.gitRevision}"
tag branch
}

buildScanPublished { scan ->
Expand Down

0 comments on commit 32df495

Please sign in to comment.