36

How can i get the Jenkins console output in a text file? I want to share it with someone, is there any way to do it?

Jay
  • 994
  • 2
  • 10
  • 20

3 Answers3

41

if you want just access the log and download it as a txt file to your workspace from the job's URL:

${BUILD_URL}/consoleText

On Linux, you can use wget to download it to your workspace

wget ${BUILD_URL}/consoleText

The actual log file on the file system is in the Master machine. You can find it under:

$JENKINS_HOME/jobs/$JOB_NAME/builds/lastSuccessfulBuild/log

Subhash
  • 1,546
  • 10
  • 17
  • Also use $WORKSPACE. – Nakilon Sep 05 '19 at 21:09
  • Thanks for this. I had to open a full console output via browser, but it was very big, my browser cannot handle it. You can change the last part of the URL from consoleFull to consoleText as noted above. While the browser is loading it, you can hit CTRL+S to save it as a txt file and open it in notepad++.

    Or as noted above, use wget or curl which should be available if you have git for windows installed (for windows users).

    – thirdy Sep 12 '19 at 01:29
4

For Windows you could use curl in a powershell prompt:

curl  ${BUILD_URL}\consoleText -OutFile C:\SomeLocation\SomeFile.txt

For MacOS:

curl  ${BUILD_URL}/consoleText -o /SomeLocation/SomeFile.txt
Yeongjun Kim
  • 103
  • 2
Will Brode
  • 141
  • 4
1

To get the Jenkins console log without curl or wget:

writeFile file: "jenkins_console_output.txt", text: currentBuild.rawBuild.logFile.text
sh 'sed -ri "s/\\x1b\\[8m.*?\\x1b\\[0m//g" jenkins_console_output.txt'

Explanation:

  • currentBuild.rawBuild.logFile.text will return annotated log.
  • \x1b\[8m.*?\x1b\[0m is a regex expression to match AnsiColorer
  • sed -ri use regexp-extended and in-place to update the file
Peter Turner
  • 1,430
  • 4
  • 17
  • 35
yoann
  • 11