How to analyze Jenkins job build logs using the log parser plugin

Reading Time: 3 minutes

Hello Readers! In this blog, we will see how we can analyze Jenkins job build logs using the log parser plugin. As we all know, Jenkins is now the most widely used CI tool. As we know job build logs in Jenkins can become very verbose sometimes, here keeping the logs in an easy format plays a very significant role. So, here is a plugin for you in this case i.e Log Parser plugin. It will make you analyze your build log in a pretty good way in Jenkins. So, let’s see how we can apply it!!

Using the Log Parser Plugin:

Step1: Set up Jenkins and create a job for which you want to use this plugin for the console build log. Use the following blog for reference: https://blog.knoldus.com/jenkins-installation-and-creation-of-freestyle-project/

Step2: Install the Log parser plugin in your Jenkins. Move to Manage Jenkins > Manage Plugins > Available > search Log parser plugin > Install. As you can see below I have already installed:

plugin

This log parser plugin will parse the console build logs which will be generated by Jenkins build. We can apply the following features in our logs by using this plugin:

  • We can categorize the build log into the sections like ERRORS, INFO, DEBUG, WARNING, and HEADER.
  • We can display these sections in summaries like the total number of errors and info on the build page.
  • We can highlight the lines of our interest in the build log as per our needs.
  • We can link the summary of errors and warnings with the full log, which makes us easy to search for a line of interest in the build log.

Step3: Next step is to write a parsing rule file that will contain the levels that we want to view in the console output log. And this file should be saved with the extension .properties or .txt. So, this a sample parser.txt file:

ok /setenv/

# match line starting with ‘error ‘, case-insensitive

error /(?i)^error /

# list of warnings here

warning /[Ww]arning/

warning /WARNING/

# creates an access link to lines in the report containing ‘SUCCESS’

info /SUCCESS/

# each line containing ‘INFO’ represents the start of a section for grouping errors and warnings found after the line.

# creates a quick access link.

start /INFO/

Step4: There are two options for adding this file. If we select the global rule inside the configuration then we have to create this file inside /var/lib/jenkins. And if we select the project rule then we have to create this file inside /var/lib/jenkins/workspace/<job_name>. So, as you can see below I have created this file:

parser.txt

Step5: Select your job configuration inside Jenkins. Open your job configuration. Inside add post build section select console output (build logs) parsing. These are the configurations that I have made:

configuration

Save and apply these configurations.

Step6: Now we will build our job and will analyze it. So, Click on Build Now. Open your console output of that build. Click on Console output (parsed). Here we can find the categories of the build logs on this page.

log parser output

So, We can see here the levels in which it is showing parsed console output. Inside info, it is highlighting the lines that we wanted. Here we can also see the log parser graph.

log parser graph

Therefore this is how we can analyze Jenkins build logs in the way that we want. It makes the build logs more useful to us.

Conclusion:

Thank you for sticking to the end. So, in this blog we have learned how we can use the log parser plugin in Jenkins to analyze our build logs. Therefore this makes our log very easy to recognize. Therefore If you like this blog, please show your appreciation by giving thumbs-ups and sharing this blog, and give me suggestions on how I can improve my future posts to suit your needs.

HAPPY LEARNING! 

Written by 

Naincy Kumari is a DevOps Consultant at Knoldus Inc. She is always ready to learn new technologies and tools. She loves painting and dancing.

Leave a Reply