Skip to content

Commit

Permalink
Create an upload report once the build completes (#47642)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alpar-t committed Oct 18, 2019
1 parent 02d18f5 commit ca99014
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
59 changes: 59 additions & 0 deletions gradle/build-complete.gradle
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
}
6 changes: 5 additions & 1 deletion gradle/build-scan.gradle
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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
}
Expand Down

0 comments on commit ca99014

Please sign in to comment.