From ca99014d8bc4e4aa40f5a439c28d58be6acb5de8 Mon Sep 17 00:00:00 2001 From: Alpar Torok Date: Fri, 18 Oct 2019 08:14:46 +0300 Subject: [PATCH] Create an upload report once the build completes (#47642) * Create an upload report once the build completes We used to have this logic in Jenkins, but that forced us to make it platform dependent and gave us less control on what to include here. With this change we create a single archive to be uploaded after the build completes, and we include a link in the build scan to where we know this should get uploaded. * Fix when there's nothign to upload * Log the directory size * Switch to ant to walk the project tree * Collect journlas * Filter for regular files * only call journalctl on unix where we have bash * Grab only logs fro this gradle version * restrict demon log to relevant one --- build.gradle | 1 + gradle/build-complete.gradle | 59 ++++++++++++++++++++++++++++++++++++ gradle/build-scan.gradle | 6 +++- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 gradle/build-complete.gradle diff --git a/build.gradle b/build.gradle index 1a651f81dc3..3e725277c83 100644 --- a/build.gradle +++ b/build.gradle @@ -40,6 +40,7 @@ plugins { apply plugin: 'nebula.info-scm' apply from: 'gradle/build-scan.gradle' +apply from: 'gradle/build-complete.gradle' // common maven publishing configuration allprojects { diff --git a/gradle/build-complete.gradle b/gradle/build-complete.gradle new file mode 100644 index 00000000000..005aa74d49c --- /dev/null +++ b/gradle/build-complete.gradle @@ -0,0 +1,59 @@ +import java.nio.file.Files +import org.elasticsearch.gradle.OS + +String buildNumber = System.getenv('BUILD_NUMBER') + +if (buildNumber) { + File uploadFile = file("build/${buildNumber}.tar.bz2") + project.gradle.buildFinished { result -> + println "build complete, generating: $uploadFile" + if (uploadFile.exists()) { + project.delete(uploadFile) + } + + OS.current() + .conditional() + .onUnix { + project.exec { + ignoreExitValue = true + workingDir projectDir + commandLine 'bash', '-c', 'journalctl --since "1 hour ago" 2>&1 > journalctl.log' + } + } + .onWindows { + + } + .onMac { + + } + + ant.tar(destfile: uploadFile, compression: "bzip2", longfile: "gnu") { + fileTree(projectDir) + .include("**/*.hprof") + .include("**/reaper.log") + .include("**/journalctl.log") + .include("**/build/testclusters/**") + .exclude("**/build/testclusters/**/data/**") + .exclude("**/build/testclusters/**/distro/**") + .exclude("**/build/testclusters/**/repo/**") + .exclude("**/build/testclusters/**/extract/**") + .filter { Files.isRegularFile(it.toPath()) } + .each { fileset(file: it) } + + + fileset(dir: "${gradle.gradleUserHomeDir}/daemon/${gradle.gradleVersion}", followsymlinks: false) { + include(name: "**/daemon-${ProcessHandle.current().pid()}*.log") + } + + if (Files.isReadable(file("/var/log/").toPath())) { + Files.list(file("/var/log/").toPath()) + .filter { it.fileName.endsWith(".log") } + .filter { Files.isReadable(it) } + .filter { Files.isRegularFile(it) } + .forEach { + fileset(file: it) + } + } + } + } +} \ No newline at end of file diff --git a/gradle/build-scan.gradle b/gradle/build-scan.gradle index 9748d3fc17d..3e47058596c 100644 --- a/gradle/build-scan.gradle +++ b/gradle/build-scan.gradle @@ -1,7 +1,9 @@ import org.elasticsearch.gradle.OS buildScan { - def jenkinsUrl = System.getenv('JENKINS_URL') ? new URL(System.getenv('JENKINS_URL')) : null + URL jenkinsUrl = System.getenv('JENKINS_URL') ? new URL(System.getenv('JENKINS_URL')) : null + String buildNumber = System.getenv('BUILD_NUMBER') + String jobName = System.getenv('JOB_NAME') tag OS.current().name() @@ -16,6 +18,8 @@ buildScan { tag 'CI' tag System.getenv('JOB_NAME') link 'Jenkins Build', System.getenv('BUILD_URL') + link 'GCP Upload', + "https://console.cloud.google.com/storage/elasticsearch-ci-artifacts/jobs/${jobName}/${buildNumber}.tar.bz2" System.getenv('NODE_LABELS').split(' ').each { value 'Jenkins Worker Label', it }