How will I filter out only errors in Jenkins-email-ext, BUILD_LOG_REGEX?
Asked Answered
K

1

9

Currently I m using BUILD_LOG_REGEX in Jenkins Editable email information to get a log of the errors via email. But I get a lot of junk and I want to filter out the errors and I want the log of errors filtered to perfection. Any help?

Kohinoor answered 24/2, 2012 at 23:20 Comment(2)
Is there some common string in the error log lines to base your regex on? If not, can you add one? Could you provide an example, which kind of regex you are using, which kind of log lines should be caught and which kind not?Lupulin
Hey Juuso, I am able to filter one kind of error now. But I would want to filter more than one kind of error. For example, An error log could be of the format Error: (or) [Error] (or) Failed: and so on and so forth. How do I make an or condition in the BUILD_LOG_REGEX ?Kohinoor
C
19

Your question is rather non-specific. As Juuso Ohtonen notes in a comment, what you do highly depends on what can be usually found in your log. Here's an example of what we use in one of our jobs, it is rather generic (if not to say minimalistic):

${BUILD_LOG_REGEX, regex="^.*?BUILD FAILED.*?$", linesBefore=0, linesAfter=10, maxMatches=5, showTruncatedLines=false, escapeHtml=true}

I would suggest the following: create a job that logs some text that contains types of errors you encounter (you may just spew some text file that you place in the job's workspace), then play with Java regex patterns - java.util.regex.Pattern - in the Plugin until you get the desired result. Make sure you send the e-mails from the job only to yourself :)

To use custom HTML - here's a quote from the Plugin's Content Token reference:

${JELLY_SCRIPT, template} - Custom message content generated from a Jelly script
  template. There are two templates provided: "html" and "text". Custom Jelly templates
  should be placed in $JENKINS_HOME/email-templates. When using custom templates, the
  template filename without ".jelly" should be used for the "template" argument.
  template - the template name. Defaults to "html".

The default template that you can use as your starting point is located in

$JENKINS_HOME/plugins/email-ext/WEB-INF/classes/hudson/plugins/emailext/templates/html.jelly
Choppy answered 26/2, 2012 at 11:5 Comment(7)
I am giving you some examples of how my log files look like. Well in this case, only the error logs (different kinds of error logs): Case:1 Error: folder mismatch - please check the following files: ============================================================================= Removed: \foo2.cs Removed: \WorkflowsHighAvailabilityApp\Application\WorkflowsHighAvailabilityApp.cs Case:2Kohinoor
My condition looks like this: ${BUILD_LOG_REGEX,regex="Error:",linesBefore=0,linesAfter=5,showTruncatedLines=false} . This filters only logs with Error:, but I want to filter error that has many kinds like [Error]/Failed: , etc. Any suggestions?Kohinoor
BUILD_LOG_REGEX uses java.util.regex.Pattern regular expressions: docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.htmlChoppy
Ok, I succeeded in filtering the error log as I wanted to using regular expressions. Now is there a way wherein I can format the way this is being displayed? Like putting this log in a table format using HTML? Can I use email-ext plugin to succeed in it? Any example?Kohinoor
Added HTML info in the body of the answerChoppy
Note, in the current version of Jenkins with email-ext, curly brace is not the syntax to put into the web form boxes. Use the same but parentheses: <code>$(BUILD_LOG_REGEX, regex="^.*?BUILD FAILED.*?$", linesBefore=0, linesAfter=10, maxMatches=5, showTruncatedLines=false, escapeHtml=true)</code>Giaimo
for at least trying to help :) Set me in right direction ^^Nonpayment

© 2022 - 2024 — McMap. All rights reserved.