Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Archiving the Jenkins build log

Tags:

jenkins

I'd like to archive the build log of every build, e.g. to a database. I know how to archive artifacts, but I don't see anything obvious for the build log.

like image 253
larsrh Avatar asked Sep 26 '22 12:09

larsrh


1 Answers

I guess you need that your job would end before you archive it. following is a groovy script with different methods to get the console log of a build. the script can be run from a another job using groovy step or scripptler step.

def jenkins = Jenkins.getInstance()
def job = jenkins.getItem(jobName)
def bld = job.getBuildByNumber(buildNumber)
//use the method that suits you
bld.getLog(100) //number of lines to read
bld.getLogFile()
bld.getLogReader() 
like image 122
Tidhar Klein Orbach Avatar answered Oct 12 '22 10:10

Tidhar Klein Orbach