Skip to content

Instantly share code, notes, and snippets.

@kulmam92
Last active May 9, 2016 18:37
Show Gist options
  • Save kulmam92/2236ce649262b896b7f8dd9f35f4a620 to your computer and use it in GitHub Desktop.
Save kulmam92/2236ce649262b896b7f8dd9f35f4a620 to your computer and use it in GitHub Desktop.
Display last changed log file in the workspace of Jenkins build - parameter : workSpace -> $workspace
def myWorkdSpace = "$workSpace"
def files = buildFileList(myWorkdSpace)
def buildFileList(dirname) {
def files = [:]
def dir = new File(dirname)
if( dir.directory ) {
dir.listFiles().each {
def path = it.absolutePath
if( it.directory ) {
files << buildFileList(it.absolutePath)
} else if( path.matches('.+\\.log') ) {
files[it.absolutePath] = it.lastModified()
}
}
}
return files
}
println "Discovered ${files.size()} files:"
def modifiedTime = 0
def newestModified
files.each { filename, modified ->
if(modified > modifiedTime) {
modifiedTime = modified
newestModified = filename
}
println "file '${filename}' '${modified}' found"
}
if(newestModified) {
println ""
println "############################################################"
println "Last modified log file is '${newestModified}'"
println "############################################################"
File file = new File(newestModified)
def linecount = file.readLines().size()-1
def topcount = 10
def i = linecount-topcount
while (i<=linecount) {
println file.readLines().get(i)
i++
}
println "############################################################"
println "End of Last modified log file"
println "############################################################"
println ""
}
if(manager.logContains("^Build FAILED.")) {
manager.buildFailure()
}
${BUILD_LOG, maxLines=50, escapeHtml=false}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment