Re: hoe to write a groovy email template to extract error message from console output

345 views
Skip to first unread message

Slide

unread,
Apr 1, 2015, 3:26:18 PM4/1/15
to jenkins...@googlegroups.com
You would probably just want to modify the template where it outputs the lines from the console to match for specific things like "error:" or whatever your error messages look like. I've done something similar to highlight warnings and errors from GCC output. It's below:

<!-- CONSOLE OUTPUT -->
<%
    if(build.result == hudson.model.Result.FAILURE) {
%>
        <TABLE width="100%" cellpadding="0" cellspacing="0">
   <TR><TD class="bg1"><B>CONSOLE OUTPUT</B></TD></TR>
<%
            build.getLog(100).each() { line ->
def styleName = line.matches('.*warning:.*') ? 'warning' : (line.matches('.*error:.*') || line.matches('.*undefined reference.*') || line.matches('.*Error:.*')) ? 'error' : 'normal'
%>
                <TR><TD class="console_${styleName}"><pre>${line}</pre></TD></TR>
<%
            }
%>      </TABLE>
        <BR/>
<%  } %>

On Wed, Apr 1, 2015 at 11:11 AM Victoria Wei Lei <weil...@gmail.com> wrote:

Helllo,

I am using parsed console log plugin and Email-ext plugin in Jenkins to send out daily build status, only upon build failure or compiler warnings. I would like to display the extracted error/warning message in the email body. I got groovy email template from "https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/resources/hudson/plugins/emailext/templates/groovy-html.template". It display Console Output instead of specific error/warning message want. I have zero knowledge on groovy or html et al, it gonna take me sometime to learn and able to modify the template to fulfill my need quickly.

Can someone point me a sample file that can search out either console output or parsed console output and only display the lines contain "error" or "warning"?

Any help is greatly appreciated.

Victoria Lei 

--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/71d20ed6-fe68-409c-8f2d-4da254aa1d1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Victoria Wei Lei

unread,
Apr 2, 2015, 11:18:41 AM4/2/15
to jenkins...@googlegroups.com
Thank you so much for you input,  let me do some experiments. 

Victoria 
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Victoria Wei Lei

unread,
Apr 2, 2015, 12:22:10 PM4/2/15
to jenkins...@googlegroups.com
It seems that current template displaying a truncated console output, below is partial output in my email:
"
Building ProductSW/Processes/TaskStarter
Creating directory cpu
C:/QNX650/Host/win32/x86/usr/bin/mkdir -p cpu
Compiling TaskStarter.c
C:/QNX650/Host/win32/x86/usr/bin/qcc -V4.4.2,gcc_ntox86 -c -Wp,-Wall -Wno-unknown-pragmas -Wp,-Wno-parentheses -DNDEBUG -DPPC_PROC=0 -DBOARD_RENUM -DCT_80 -DTMRU_QNX -msse -msse2 -msse3 -march=prescott -mfpmath=sse -mstackrealign -O  -Wp,-MD -Wp,cpu/TaskStarter.d -IC:\Jenkins_buildslave_gen3\workspace\testjob/Processes/IPMI -IC:\Jenkins_buildslave_gen3\workspace\testjob/QNX_BSP/BSP/src/hardware/startup/lib/x86 -IC:\Jenkins_buildslave_gen3\workspace\testjob/QNX_BSP/BSP/src/hardware/startup/lib/ -IC:\Jenkins_buildslave_gen3\workspace\testjob/Processes/POST -I../Include  -I../../Include -I../../Include\TMSC -I../../Include\Status 
-IC:\Intel\libraries\ipp41\ia32_itanium\include -IC:\Intel\libraries\ipp41\ia32_itanium\tools\staticlib TaskStarter.c -o cpu/TaskStarter.o
TaskStarter.c: In function &apos;main&apos;:
TaskStarter.c:72: error: expected expression before &apos;<<&apos; token
cc: C:/QNX650/host/win32/x86/usr/lib/gcc/i486-pc-nto-qnx6.5.0/4.4.2/cc1 caught signal 1
make[2]: *** [TaskStarter.o] Error 1
make[2]: Leaving directory `C:/Jenkins_buildslave_gen3/workspace/testjob/Processes/TaskStarter&apos;
make[1]: *** [TaskStarter.y] Error 2
make[1]: Leaving directory `C:/Jenkins_buildslave_gen3/workspace/testjob/Processes&apos;
make: *** [Processes.y] Error 2
end   rtm ct80 Thu Apr  2 11:04:50 2015
start sample ct80 Thu Apr  2 11:04:50 2015
Changing to C:\Jenkins_buildslave_gen3\workspace\testjob\TMSC_Sample 
Making the Sample"

what I really interested is to only display below lines what contains Error"
"TaskStarter.c:72: error: expected expression before '<<' token

make[2]: *** [TaskStarter.o] Error 1

make[1]: *** [TaskStarter.y] Error 2

make: *** [Processes.y] Error 2"

what should I do? 

Thanks


On Wednesday, April 1, 2015 at 2:26:18 PM UTC-5, slide wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Slide

unread,
Apr 2, 2015, 12:50:49 PM4/2/15
to jenkins...@googlegroups.com

If you are using what I wrote, it only gets the last 100 lines of the log. You would need to change that somehow to get the information you want.


Victoria Wei Lei

unread,
Apr 6, 2015, 11:56:24 AM4/6/15
to jenkins...@googlegroups.com
Hi, 

I thought your  following code searches error/warning for each line, and only display the lines that contain the message:
"<%
            build.getLog(100).each() { line ->
def styleName = line.matches('.*warning:.*') ? 'warning' : (line.matches('.*error:.*') || line.matches('.*undefined reference.*') || line.matches('.*Error:.*')) ? 'error' : 'normal'
%>
                <TR><TD class="console_${styleName}"><pre>${line}</pre></TD></TR>"

sorry, I don't quite know the groovy script yet, what's the purpose to define StyleName? 

I tried another sample which supposed to scan the lines contain "error", but it does not produce filtered output either,  any idea? 
<!-- CONSOLE OUTPUT -->
<%
    if(build.result == hudson.model.Result.FAILURE) {
%>
        <TABLE width="100%" cellpadding="0" cellspacing="0">
   <TR><TD class="bg1"><B>PARSED OUTPUT</B></TD></TR>
<%      def rdr= new InputStreamReader(build.getLogInputStream())
        rdr.eachLine{ it -> 
      if(it.contains("[error]")) {
          def line= hudson.console.ConsoleNote.removeNotes(it)  %>
          <TR><TD class="console"><pre>${line}</pre></TD></TR>
<%
            }
%>      </TABLE>
        <BR/>
<%  } %>
<% } %>

Thank you!
Victoria 

Slide

unread,
Apr 6, 2015, 12:00:13 PM4/6/15
to jenkins...@googlegroups.com
I think you are asking the wrong person, I am the one that pasted that template code. For me in that code, I just highlight the errors with a particular CSS style, so that warnings show up in yellow, errors in red, etc. The styles are defined higher up in my template.

Victoria Wei Lei

unread,
Apr 6, 2015, 1:10:24 PM4/6/15
to jenkins...@googlegroups.com

i see.  thanks for the explanation. 
Reply all
Reply to author
Forward
0 new messages