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

user1048613 picture user1048613 · Feb 25, 2012 · Viewed 15.5k times · Source

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?

Answer

malenkiy_scot picture malenkiy_scot · Feb 26, 2012

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