How to analyze Jenkins Build logs using the ELK stack

two businessmen outdoor using technology
Reading Time: 3 minutes

Hello Readers! In this blog, we are going to see how we can analyze Jenkins build logs using the ELK stack. As Jenkins is known for its automation and we have a number of its builds logs. Here analysis of Jenkins build logs plays a huge role. So, I will explain and show you how we can monitor and analyze Jenkins build logs in our kibana dashboard.

Prerequisites:

  1. Jenkins should be up and running. Follow the following blog for the setup of Jenkins: https://blog.knoldus.com/jenkins-installation-and-creation-of-freestyle-project/
  2. Set up the ELK stack. Follow the blog for installation:

https://phoenixnap.com/kb/install-elasticsearch-ubuntu

https://www.elastic.co/guide/en/kibana/7.17/deb.html

My elastic search and kibana are in a running state as you can see below:

elastic search
kibana

Let’s start!

Step 1: Install the logstash plugin in Jenkins. Go to Manage Jenkins>Manage Plugins>Available

install logstash

It is now installed for me.

install plugin

Step 2: Create a Jenkins job. For me, it will be a freestyle project.

create job

Now we will configure this Jenkins job. Select send console log to Logstash.

configure jenkins

Inside Post-build actions, Select send console log in Logstash.

jenkins

Add your GitHub project to Jenkins which you want to build.

add project

Save the configuration and apply it.

Step 3: Go to Manage Jenkins > Global Tool Configuration.

jenkins

Select Logstash plugin.

plugin

Inside this fill in the details of Elasticsearch. Inside elasticsearch URI fill in http://localhost:9200/yourindex_name/yourindex_type. My index name will be Jenkinsdata which I will create in the next step. Fill in as per your wish.

logstash

Save and apply it.

Step 4: Create an index in elasticsearch which we have mentioned above step. All the Jenkins job build logs will be sent to this particular index only. Create it by sending a request using the PUT method.

index

My index is created successfully.

Step 5: Create an index pattern in kibana. Move to Kibana > Management > Index pattern. Select your index and create an index pattern. We can analyze our logs using this pattern in kibana.

index pattern

Step 6: Now we are all set. Just Build that Jenkins job and finally move to Kibana > Discover. You can see your build logs details thereby selecting the index pattern.

kibana dashboard

Apply the filters as per your requirement. We have sent all our Jenkins build logs to elastic search and visualized those logs using Kibana. 

We are all done now!!!

Conclusion:

Thank you for sticking to the end with me. In this blog, we have seen how we can analyze Jenkins build logs using the ELK stack. If you like this blog, please share my blog and show your appreciation by giving thumbs-ups, and don’t forget to give me suggestions on how I can improve my future blogs that can 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.