Hudson SiteMonitor Plugin and JSLint Violations Support

Hudson SiteMonitor Plugin and JSLint Violations Support

Late last December, Shine allowed me to spend a couple of days working on some Hudson contributions. I was planning to finish 3-4 plugins, but used up too much time trying various approaches and testing various scenarios. I actually ended up with unfinished implementations back then.

Fast forward to last week, I finally managed to spend a little bit of my own time to finish the plugin(s), and I also accidentally found a bug with Recorder#perform’s return value being ignored from build status determination. Contacted the dev list and Kohsuke has since fixed it in r29836, the fix will be included in Hudson 1.354.

The first plugin I worked on was SiteMonitor Plugin, it’s basically used for monitoring a web site’s up/down status. At work we used to do this by using Ant Conditions Task, I know other people who use wget and various tools to achieve the same result. I just thought it would be much simpler for a Hudson user to be able to install a plugin and add some URLs to monitor without the need to implement any script.

Here’s how SiteMonitor Plugin looks like:

the report

job configuration

global configuration

This plugin is still at an early stage and currently only reports response code and up/down status of a web site. It doesn’t have any roadmap per se, but I think future versions of the plugin should have more Pingdom-like features and reports. If you have any request or suggestion, feel free to leave a comment on this blog or raise a JIRA issue and assign it to me.

The rest of my December effort went to JSLint reporting, which ended up as such a simple enhancement to Violations Plugin. It was initially implemented as a standalone plugin, first, it attempted to include a simple Java wrapper for JSLint, a parser for JSLint’s text output, and a report generator. The initial implementation was ditched when I found out that there’s already jslint4java.

So I decided to leave the JSLint handling up to the project being built itself, and the plugin implementation only takes care of output parsing (jslint4java provides a nice XML output on top of JSLint’s default text output) and generating a report page. I used Checkstyle Plugin as a base for my implementation. But this effort was also then scrapped after I found out that Violations Plugin already provides all the groundwork necessary for code violations (duh!) reporting.

Adding JSLint as another type of violations was way too easy in Violations Plugin.

Here’s how JSLint report looks like:

All in all, Hudson’s large array of plugins is a proof of how extensible it is as a platform. Creating new plugins isn’t that hard and Hudson API is quite pleasant to work with. I hope these two little contributions could be useful for someone out there.

Cliffano Subagio
cliff.subagio@shinesolutions.com
14 Comments
  • Dominic Mitchell
    Posted at 20:02h, 13 April Reply

    I’m glad you found jslint4java useful. Let me know if it does something you don’t expect. 🙂

  • Thomas Wajs
    Posted at 00:05h, 28 April Reply

    When you say that “Adding JSLint as another type of violations was way too easy in Violations Plugin.”, what are you refering to ?

    I couldn’t find where to do that.

  • cliffs
    Posted at 09:29h, 28 April Reply

    Hi Thomas,

    I was referring to how easy it was to add JSLint reporting to Violations Plugin source code. Adding a new type of reporting only requires you to add a descriptor and a parser, without having to worry about report rendering, the extension point, etc.

    Please note that this change hasn’t been released yet, it’s still currently in Violations Plugin 0.7.6-SNAPSHOT, but I’ve been using it for several months so I can verify that it’s stable enough.

    Let me know if you prefer not to build the SNAPSHOT from trunk, I’ll try to push the official release of 0.7.6 .

    Hi Dom,

    jslint4java works great, no problem whatsoever, thanks :).

  • Thomas Wajs
    Posted at 22:58h, 28 April Reply

    Thanks for the reply, I thought it was already available somewhere through the Hudson/Violation GUI.

    Actually I’ve never built myself an Hudson plugin, so I’m kinda lost in how to achieve that. If it’s straightforward or if there is a tutorial somewhere, I may take some time to dig into, but otherwise I’ll wait patiently for the official release to show up. I’m not in a rush, so I can afford the waiting.

  • cliffs
    Posted at 23:05h, 01 May Reply

    There’s still a StyleCop bug fix work going on, so unfortunately I can’t organise a release yet.

    I have built the SNAPSHOT version with JSLint support, you can download it from http://dl.dropbox.com/u/1934042/violations-0.7.6-SNAPSHOT-20100501.hpi , and install it on your Hudson instance.

    FYI, to build the SNAPSHOT version you’ll need to:
    – checkout Hudson source
    – go to plugins/violations directory
    – run ‘mvn package’ (assuming you already have http://maven.apache.org installed)
    – the SNAPSHOT build will be created at plugins/violations/target directory

  • knalli
    Posted at 18:18h, 15 June Reply

    Hi,
    I’m following your approach of JSLint and CheckStyle/Hudson. What is the current status of the plugin or, actually, the stylecop issue?

    Without building hudson on myself: I can’t use the plugin, right?

  • Cliffano Subagio
    Posted at 15:26h, 01 August Reply

    Hi Knalli,

    If you don’t want to build the trunk yourself, you can download the daily build I linked on my previous comment.

    Since it’s been a while since there’s any activity with Violations plugin source, I went ahead and release 0.7.6, it should be available for download soon from http://hudson-ci.org/download/plugins/violations/ .

  • knalli
    Posted at 21:50h, 02 August Reply

    Hi Cliff,

    seems that I’ve missed the “daily build” link.. or I’d some trouble with it. Anyway, an actual release is a good way. Thank you!

    knalli

  • vma
    Posted at 17:32h, 08 October Reply

    Hi,

    Am I using jslint4java in a wrong way (java -jar jslint4java-1.4.2.jar jsfiletobeanalyzed.js > jslint.txt)? I get the following trace from violation plug-in (v0.7.6):

    ERROR: Publisher hudson.plugins.violations.ViolationsPublisher aborted due to exception
    hudson.util.IOException2: Cannot parse trunk/project/jslint.txt
    at hudson.plugins.violations.parse.AbstractTypeParser.parse(AbstractTypeParser.java:64)
    at hudson.plugins.violations.ViolationsCollector.doType(ViolationsCollector.java:189)
    at hudson.plugins.violations.ViolationsCollector.invoke(ViolationsCollector.java:116)
    at hudson.plugins.violations.ViolationsCollector.invoke(ViolationsCollector.java:27)
    at hudson.FilePath.act(FilePath.java:753)
    at hudson.FilePath.act(FilePath.java:735)
    at hudson.plugins.violations.ViolationsPublisher.perform(ViolationsPublisher.java:74)
    at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
    at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:601)
    at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:580)
    at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:558)
    at hudson.model.Build$RunnerImpl.post2(Build.java:157)
    at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:528)
    at hudson.model.Run.run(Run.java:1296)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:137)
    Caused by: org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not j (position: START_DOCUMENT seen j… @1:1)
    at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1519)
    at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395)
    at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
    at hudson.plugins.violations.parse.AbstractParser.expectNextTag(AbstractParser.java:262)
    at hudson.plugins.violations.types.jslint.JsLintParser.execute(JsLintParser.java:25)
    at hudson.plugins.violations.parse.AbstractTypeParser.parse(AbstractTypeParser.java:59)

    BR.
    VMA

  • Mike Pilsbury
    Posted at 17:19h, 06 November Reply

    vma,

    It looks like you might have made the same mistake as I did initially. What the Violations plugin is expecting in the “XML filename pattern” field is not the Javascript files, but the XML output from jslint4java’s Ant task.

    Mike

  • Sebastian
    Posted at 20:50h, 28 June Reply

    hi Cliff,

    Google brought me here :). I’m currently trying out jslint using jslint4java/ant/hudson. The violations plugin is reporting but the graphs are not drawn. Any idea on that?

  • Sebastian
    Posted at 22:19h, 28 June Reply

    Nvm, seems to be a jslint4java issue.

  • Cliffano Subagio
    Posted at 22:48h, 28 June Reply

    @Sebastian Glad you’ve figured it out. When there’s a weird error, try checking Jenkins/Hudson log file, you’ll usually find an error stack trace there.

  • test
    Posted at 08:53h, 09 December Reply

    Hey just wanted to give you a quick heads up and let you know a few of the pictures aren’t loading correctly. I’m not sure why but I think
    its a linking issue. I’ve tried it in two different web browsers and both show the same results.

Leave a Reply

%d bloggers like this: