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
This commit is contained in:
Alpar Torok 2019-10-18 08:14:46 +03:00
parent 02d18f5c1e
commit ca99014d8b
3 changed files with 65 additions and 1 deletions

View File

@ -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 {

View File

@ -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)
}
}
}
}
}

View File

@ -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
}