Jenkins “Console Output” log location in filesystem

后端 未结 8 2532
自闭症患者
自闭症患者 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: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.

提交回复
热议问题