2

I want all my jenkins logs of my current build in groovy

env.logs = currentBuild.rawBuild.getLog(1000).join('\n')

This works, but the problem here is I have to specify the amount of lines. When I use:

env.logs = currentBuild.rawBuild.getLog().join('\n')

env.logs is empty. What is the right command to get all the logs without specifying the amount of lines. Is this possible?

currentBuild.rawBuild.log seems to work but is deprecated?

DenCowboy
  • 13,884
  • 38
  • 114
  • 210

2 Answers2

2

You can use the getLog method with a max value getLog(Integer.MAX_VALUE)

yamenk
  • 46,736
  • 10
  • 93
  • 87
  • seems not to work for me? It remains empty. Do I have to import a specific class? On what is the integer.MAX_VALUE based? – DenCowboy Dec 06 '17 at 08:47
0

This is working for me - it reads the actual log file instead of using the API:

logFileContent = new File("${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_NUMBER}/log").collect {it}
Max Cascone
  • 648
  • 9
  • 25