Jenkins “Console Output” log location in filesystem

后端 未结 8 2408
自闭症患者
自闭症患者 2020-12-13 12:56

I want to access and grep Jenkins Console Output as a post build step in the same job that creates this output. Redirecting logs with >> log.txt is not a

相关标签:
8条回答
  • 2020-12-13 13:15

    For very large output logs it could be difficult to open (network delay, scrolling). This is the solution I'm using to check big log files:

        https://${URL}/jenkins/job/${jobName}/${buildNumber}/
    

    in the left column you see: View as plain text. Do a right mouse click on it and choose save links as. Now you can save your big log as .txt file. Open it with notepad++ and you can go through your logs easily without network delays during scrolling.

    0 讨论(0)
  • 2020-12-13 13:21

    You can install this Jenkins Console log plugin to write the log in your workspace as a post build step.

    You have to build the plugin yourself and install the plugin manually.

    Next, you can add a post build step like that:

    With an additional post build step (shell script), you will be able to grep your log.

    I hope it helped :)

    0 讨论(0)
  • 2020-12-13 13:26

    Log location:

    ${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_NUMBER}/log
    

    Get log as a text and save to workspace:

    cat ${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_NUMBER}/log >> log.txt
    
    0 讨论(0)
  • 2020-12-13 13:28

    Easy solution would be:

    curl  http://jenkinsUrl/job/<Build_Name>/<Build_Number>/consoleText -OutFile <FilePathToLocalDisk>
    

    or for the last successful build...

    curl  http://jenkinsUrl/job/<Build_Name>/lastSuccessfulBuild/consoleText -OutFile <FilePathToLocalDisk>
    
    0 讨论(0)
  • 2020-12-13 13:30

    This is designed for use when you have a shell script build step. Use only the first two lines to get the file name.

    You can get the console log file (using bash magic) for the current build from a shell script this way and check it for some error string, failing the job if found:

    logFilename=${JENKINS_HOME}/${JOB_URL:${#JENKINS_URL}}
    logFilename=${logFilename//job\//jobs\/}builds/${BUILD_NUMBER}/log
    
    grep "**Failure**" ${logFilename} ; exitCode=$?
    [[ $exitCode -ne 1 ]] && exit 1
    

    You have to build the file name by taking the JOB_URL, stripping off the leading host name part, adding in the path to JENKINS_HOME, replacing "/job/" to "/jobs/" to handle all nested folders, adding the current build number and the file name.

    The grep returns 0 if the string is found and 2 if there is a file error. So a 1 means it found the error indication string. That makes the build fail.

    0 讨论(0)
  • 2020-12-13 13:32

    @Bruno Lavit has a great answer, but if you want you can just access the log and download it as txt file to your workspace from the job's URL:

    ${BUILD_URL}/consoleText
    

    Then it's only a matter of downloading this page to your ${Workspace}

    • You can use "Invoke ANT" and use the GET target
    • On Linux you can use wget to download it to your workspace
    • etc.

    Good luck!

    Edit: The actual log file on the file system is not on the slave, but kept in the Master machine. You can find it under: $JENKINS_HOME/jobs/$JOB_NAME/builds/lastSuccessfulBuild/log

    If you're looking for another build just replace lastSuccessfulBuild with the build you're looking for.

    0 讨论(0)
提交回复
热议问题