Answering my own question in case it may help someone. I put this in my
"failure" post action section of my Jenkinsfile to extract the last 100
lines of the build log. I also filtered out the post actions output and
the leading rubbish on each line of the actual build log.
jobName = "${env.JOB_NAME}"
tokens = jobName.split('/')
jobDir = tokens[0]
logFile =
"${env.JENKINS_HOME}/jobs/${jobDir}/branches/${env.JOB_BASE_NAME}/builds/${env.BUILD_NUMBER}/log"
command = $/tail -100 ${logFile} | sed '/Post Actions/q' | sed
'/\[Pipeline\]/d' | sed -e 's/^.*\[0m//g'/$
logSnippet = sh(script: command, returnStdout: true)
On Monday, September 4, 2017 at 10:27:52 AM UTC-5, Dallas Clement wrote:
>
> I've done all that. What I want is to extract the last portion of the
> actual console output for a build that has failed so that I can embed it in
> the body of an email notification to indicate where the build has failed.
> I'm trying to avoid attaching the whole build log. I've been able to
> locate the build log, but I don't know how to extract the raw console
> output from it.
>
> On Monday, September 4, 2017 at 6:14:56 AM UTC-5, xwyxw wrote:
>>
>> Blueoncean, split your script in functions and stages and you will get
>> a good understanding of what is actually happening on every stage (clone,
>> build, fail, etc). Also using groovy and try/catch will help too
>>
>> On Friday, September 1, 2017 at 2:25:05 AM UTC+10, Dallas Clement wrote:
>>>
>>> I am working with multibranch pipeline builds and I want to be able to
>>> tail the end of the console output to include in build failure email
>>> notifications. I can see where the log file is located in the filesystem
>>> under
>>>
>>> /var/lib/jenkins/jobs/<name of project>/branches/<name of
>>> branch>/builds/5
>>>
>>> The build log appears to have the console output embedded in it. But
>>> there appears to be a whole lot more also. How can I extract / render just
>>> the console output?
>>>
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/1baad50f-780d-4296-96cb-030a26683fca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.