email-ext groovy parsing build log question

390 views
Skip to first unread message

Steven Deal

unread,
Dec 18, 2013, 9:16:20 AM12/18/13
to jenkins...@googlegroups.com
Backstory: our build produces a 35000+ line log file (forget turning down the logging level). A compile error or such might be scattered anywhere over this output and typically will not be in the last few lines. Build emails became nearly useless as they rarely showed a developer what actually failed the build. To fix this, I started making more use of a custom groovy template and the email-ext plugin to parse out just the errors from the build log. Something like:

<%      def rdr= new InputStreamReader(build.getLogInputStream()) %>

<%      rdr.eachLine{ it -> %>

<%        if(it.contains("[error]")) { %>

<%           def line= hudson.console.ConsoleNote.removeNotes(it) %>

             <TR><TD class="console">${line}</TD></TR>

<%        } %>


This worked great from my standpoint. However, many of my developers check their email through gmail, which clips the message at a certain size. Investigating this, I noticed that the raw source of the email contained hundreds of blank lines. Basically, it looks like every line of groovy code produces an empty line in the email. So looping through this whole log file produces an insane number of blank lines. I suspect this extra content is what's causing gmail to clip the message. Given I don't want developers to have to click through the email to see the compile error, is there an alternative to avoid this within email-ext/groovy?
-steven

Daniel Beck

unread,
Dec 18, 2013, 3:22:01 PM12/18/13
to jenkins...@googlegroups.com
You can wrap multiple lines in <% %>. The way you wrap each line individually works, but every line break between %> and %< gets printed.

Instead, do it like this:

> <% def rdr= new InputStreamReader(build.getLogInputStream())
> rdr.eachLine{ it ->
> if(it.contains("[error]")) {
> def line= hudson.console.ConsoleNote.removeNotes(it) %>
> <TR><TD class="console">${line}</TD></TR>
> <% } %>

> --
> 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 jenkinsci-use...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Steven Deal

unread,
Dec 19, 2013, 7:45:00 AM12/19/13
to jenkins...@googlegroups.com
Thanks, this is good to know and first experiments have my message not getting clipped in gmail, so your suggestion worked.


You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/TMD3RedSF9A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.

Victoria Wei Lei

unread,
Apr 2, 2015, 4:20:56 PM4/2/15
to jenkins...@googlegroups.com
hello, Steven, 

Hope my message reach you out. 
I used your sample code and replaced the string I want to extract from console log, it would not do anything. 
I chnage it as text format:

<%      def rdr= new InputStreamReader(build.getLogInputStream()) %>
<%        rdr.eachLine{ it -> %>
<%         if(it.contains("[SVN]")) { %>
<%            def line= hudson.console.ConsoleNote.removeNotes(it) %> 
              ${line} 
<%        }  
} %>

I will really appreciate it if you can point out what's wrong.  (it seems yours was HTML,  I change it to text format)

Thanks
Victoria 

Steven Deal

unread,
Apr 2, 2015, 4:33:53 PM4/2/15
to jenkins...@googlegroups.com
Hi Victoria,
I see nothing wrong with what you have. I think the string you are looking for would have to be '[SVN]', i.e. it's not a regular expression. You may wish to change this to simply 'SVN' to see something captured. Are you getting an error or simply not output?

Victoria Wei Lei

unread,
Apr 2, 2015, 10:17:58 PM4/2/15
to jenkins...@googlegroups.com
Hi, Steven, 

currently it does not generate any output.  i am running very simple test program, and SVN is definitely showing in console output, so I replace "error' in your template with SVN.  My goal is to scan our build console output,  and only display the lines containing "error[s]' or "warning[s]" in the email body.   your template was supposed to achieve the same thing, right? and also,  is this code executed regardless of Jenkins build Status (SUCCESS/FAILURE/UNSTABLE)?  

Thank you so much for your reply,  please let me know if you have more clues. At the mean while,  I will try more.

Victoria 
Reply all
Reply to author
Forward
0 new messages