|
8 | 8 |
|
9 | 9 | import java.nio.file.Files
|
10 | 10 |
|
11 |
| -String buildNumber = System.getenv('BUILD_NUMBER') |
| 11 | +String buildNumber = System.getenv('BUILD_NUMBER') ?: System.getenv('BUILDKITE_BUILD_NUMBER') |
12 | 12 |
|
13 | 13 | if (buildNumber) {
|
14 |
| - File uploadFile = file("build/${buildNumber}.tar.bz2") |
| 14 | + def uploadFilePath = "build/${buildNumber}.tar.bz2" |
| 15 | + File uploadFile = file(uploadFilePath) |
15 | 16 | project.gradle.buildFinished { result ->
|
16 | 17 | println "build complete, generating: $uploadFile"
|
17 | 18 | if (uploadFile.exists()) {
|
@@ -62,5 +63,27 @@ if (buildNumber) {
|
62 | 63 | } catch (Exception e) {
|
63 | 64 | logger.lifecycle("Failed to archive additional logs", e)
|
64 | 65 | }
|
| 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 | + } |
65 | 88 | }
|
66 | 89 | }
|
0 commit comments