Monitor your cron jobs with Jenkins

Have you found yourself having some cron jobs failing for a while before you realize it when checking the user’s mailbox on that machine? How about having a web dashboard that will give you an “at a glance” status of these?

Here comes Jenkins — http://jenkins-ci.org . The tool is java-based. It is a tool that actually monitors automatic builds of java code for example, or watch over cron jobs. It is meant to be part of the Continuous Integration concept.

Let’s create a simple example; We will use this job to capture the console output of a trivial command, ls -l. This is on mac OSX.
Download jenkins from the homepage. Installation is fairly straight forward, and on mac anyway, your browser opens up automatically with http://localhost:8080 to present you with the Jenkins dashboard.

Let’s create a new job in this interface. Select “Monitor an external job” and give a meaningful name. Press OK.
Jenkins job creation
On the next screen, enter a description then save.

If you go back to the dashboard, your newly created job appears and do not present any data yet.
dashboard

– Open a terminal.
– Set JENKINS_HOME
[sourcecode language=’bash’]export JENKINS_HOME=http:/@localhost:8080/[/sourcecode]

– Find out where your “jenkins-core” file is. The exact name depends on the version you downloaded.
On Max OSX, and in my particular case, it is located at
[sourcecode language=’bash’]/Users/Shared/Jenkins/Home/war/WEB-INF/lib/jenkins-core-1.500.jar[/sourcecode]

Now, we will prepend the actual command we want to monitor with the jenkins java command, and associate it with the job name we created above.
[sourcecode language=’bash’]java -jar /Users/Shared/Jenkins/Home/war/WEB-INF/lib/jenkins-core-1.500.jar “List home directory” ls -l[/sourcecode]
command line

If you now go back to the dashboard and hit refresh, you will see the status change.
Status update dashboard

Click on the job, and then on the permalink “last build” (if you hover the link, a small pop-up appears)
build output

And there you can see your console output
console output

Therefore, if you were to have a cron jobs that you want to monitor you would just have to follow the same steps, making sure JENKINS_HOME is exported, and the output under the right job name.
And you have it all in a web dashboard!

If you want an example of a well fed dashboard, you can visit apache’s at Apache’s builds website

Leave a Reply