Getting Data In

How to send few values from jenkins pipeline to splunk and report it

sendilprakash
Explorer

Hi,

Thanks in advance for your help.

I am new to splunk and working on building few reports in splunk from Jenkins. Here is my requirement:

I have only one jenkins pipeline job which serves as deploy job for any release (example windows 7, windows 8, windows 10). Now I want to report the latest build ran for any release. I have this release value in a variable in jenkins job. Now how do I pass this release information to splunk along with other values. Currently I can see jenkins jobname, job number, url, etc.. values in splunk . Please find below attachment. I want to show 'Release' as field in splunk so that I can use it in query.

alt textalt text

0 Karma
1 Solution

sendilprakash
Explorer

I answer my own question:

By using splunkins.send(msg) I am able to pass on my application,build and release details as key value pair to splunk and in splunk I can see each parameter I send from jenkins as a field in splunk and I can build my dashboards.

Here is my pipeline script to send my application,build and release details to splunk

stage('send_input_start')
{
    jobtype = "build"
    branch = "dev"
    application = "My Application"
    component = "My Component"
    release = "My Release"
    jstatus = "Started"
    jresult = "Building"
    msg = "BNum="+BUILD_NUMBER+",JName="+JOB_NAME+",AppName="+application+",CompName="+component+",BranchName="+branch+",RelNumber="+release+",JobStatus="+jstatus+",JobResult="+jresult+",JType="+jobtype
    splunkins.send(msg)
}

In the above code ensure that you append all your build, application and release details in the same way to variable msg(in my case). Otherwise splunk is not recognizing them as fields.

on the splunk side here is the query to see the data that you sent.

sourcetype="text:jenkins" BNum=10 AppName="My Application" RelNumber="My Release"

View solution in original post

sendilprakash
Explorer

I answer my own question:

By using splunkins.send(msg) I am able to pass on my application,build and release details as key value pair to splunk and in splunk I can see each parameter I send from jenkins as a field in splunk and I can build my dashboards.

Here is my pipeline script to send my application,build and release details to splunk

stage('send_input_start')
{
    jobtype = "build"
    branch = "dev"
    application = "My Application"
    component = "My Component"
    release = "My Release"
    jstatus = "Started"
    jresult = "Building"
    msg = "BNum="+BUILD_NUMBER+",JName="+JOB_NAME+",AppName="+application+",CompName="+component+",BranchName="+branch+",RelNumber="+release+",JobStatus="+jstatus+",JobResult="+jresult+",JType="+jobtype
    splunkins.send(msg)
}

In the above code ensure that you append all your build, application and release details in the same way to variable msg(in my case). Otherwise splunk is not recognizing them as fields.

on the splunk side here is the query to see the data that you sent.

sourcetype="text:jenkins" BNum=10 AppName="My Application" RelNumber="My Release"

Get Updates on the Splunk Community!

Get Inspired! We’ve Got Validation that Your Hard Work is Paying Off

We love our Splunk Community and want you to feel inspired by all your hard work! Eric Fusilero, our VP of ...

What's New in Splunk Enterprise 9.4: Features to Power Your Digital Resilience

Hey Splunky People! We are excited to share the latest updates in Splunk Enterprise 9.4. In this release we ...

Take Your Breath Away with Splunk Risk-Based Alerting (RBA)

WATCH NOW!The Splunk Guide to Risk-Based Alerting is here to empower your SOC like never before. Join Haylee ...