Skip to content

Commit

Permalink
Move the artifact build scan stuff to build-complete
Browse files Browse the repository at this point in the history
  • Loading branch information
brianseeders committed Oct 13, 2023
1 parent cabd1b3 commit 5137f81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ if (buildNumber && performanceTest == null && GradleUtils.isIncludedBuild(projec
new ProcessBuilder("buildkite-agent", "artifact", "upload", uploadFilePath)
.start()
.waitFor()

def process = new ProcessBuilder("buildkite-agent", "artifact", "search", uploadFilePath, "--step", System.getenv('BUILDKITE_JOB_ID'), "--format", "%i").start()
process.waitFor()
println("Output: " + process.text)
def artifactUuid = (process.text ?: "").trim()
if (artifactUuid) {
buildScan.link 'Artifact Upload', "https://buildkite.com/organizations/elastic/pipelines/${System.getenv('BUILDKITE_PIPELINE_SLUG')}/builds/${buildNumber}/jobs/${System.getenv('BUILDKITE_JOB_ID')}/artifacts/${artifactUuid}"
}
} catch (Exception e) {
logger.lifecycle("Failed to upload buildkite artifact", e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ buildScan {
buildScan.server = 'https://gradle-enterprise.elastic.co'
}

// background {
background {
tag OS.current().name()
tag Architecture.current().name()

Expand Down Expand Up @@ -102,7 +102,8 @@ buildScan {
tag 'CI'
link 'CI Build', buildKiteUrl
value 'Job Number', buildNumber

value 'Pipeline', System.getenv('BUILDKITE_PIPELINE_SLUG')
value 'Job Name', System.getenv('BUILDKITE_LABEL')

// Add SCM information
def prId = System.getenv('BUILDKITE_PULL_REQUEST')
Expand All @@ -119,25 +120,6 @@ buildScan {
tag branch
}

def uploadFilePath = "build/${buildNumber}.tar.bz2"
File uploadFile = file(uploadFilePath)

buildFinished {
println(uploadFilePath)

if (uploadFile.exists()) {
println("exists, searching " + ["buildkite-agent", "artifact", "search", uploadFilePath, "--step", System.getenv('BUILDKITE_JOB_ID'), "--format", "%i"].join(" "))

def process = new ProcessBuilder("buildkite-agent", "artifact", "search", uploadFilePath, "--step", System.getenv('BUILDKITE_JOB_ID'), "--format", "%i").start()
process.waitFor()
println("Output: " + process.text)
def artifactUuid = (process.text ?: "").trim()
if (artifactUuid) {
link 'Artifact Upload', "https://buildkite.com/organizations/elastic/pipelines/${System.getenv('BUILDKITE_PIPELINE_SLUG')}/builds/${buildNumber}/jobs/${System.getenv('BUILDKITE_JOB_ID')}/artifacts/${artifactUuid}"
}
}
}

buildScanPublished { scan ->
// Attach build scan link as build metadata
// See: https://buildkite.com/docs/pipelines/build-meta-data
Expand All @@ -155,5 +137,5 @@ buildScan {
} else {
tag 'LOCAL'
}
// }
}
}

0 comments on commit 5137f81

Please sign in to comment.