Skip to content

Commit 2939c26

Browse files
authored
[7.17] [buildkite] Upload build artifact and add to build scan (#100842) (#100861)
1 parent 8196483 commit 2939c26

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

build-tools-internal/src/main/groovy/elasticsearch.build-complete.gradle

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
import java.nio.file.Files
1010

11-
String buildNumber = System.getenv('BUILD_NUMBER')
11+
String buildNumber = System.getenv('BUILD_NUMBER') ?: System.getenv('BUILDKITE_BUILD_NUMBER')
1212

1313
if (buildNumber) {
14-
File uploadFile = file("build/${buildNumber}.tar.bz2")
14+
def uploadFilePath = "build/${buildNumber}.tar.bz2"
15+
File uploadFile = file(uploadFilePath)
1516
project.gradle.buildFinished { result ->
1617
println "build complete, generating: $uploadFile"
1718
if (uploadFile.exists()) {
@@ -62,5 +63,27 @@ if (buildNumber) {
6263
} catch (Exception e) {
6364
logger.lifecycle("Failed to archive additional logs", e)
6465
}
66+
67+
if (uploadFile.exists() && System.getenv("BUILDKITE") == "true") {
68+
try {
69+
println "Uploading buildkite artifact: ${uploadFilePath}..."
70+
new ProcessBuilder("buildkite-agent", "artifact", "upload", uploadFilePath)
71+
.start()
72+
.waitFor()
73+
74+
println "Generating buildscan link for artifact..."
75+
76+
def process = new ProcessBuilder("buildkite-agent", "artifact", "search", uploadFilePath, "--step", System.getenv('BUILDKITE_JOB_ID'), "--format", "%i").start()
77+
process.waitFor()
78+
def artifactUuid = (process.text ?: "").trim()
79+
80+
println "Artifact UUID: ${artifactUuid}"
81+
if (artifactUuid) {
82+
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}"
83+
}
84+
} catch (Exception e) {
85+
logger.lifecycle("Failed to upload buildkite artifact", e)
86+
}
87+
}
6588
}
6689
}

0 commit comments

Comments
 (0)