A couple of people have asked about how to get Prospector working as part of the Jenkins CI server. There are a couple of compatability modes for Prospector which should allow it to be a drop-in replacement for pylint, so until there is better support, here are some instructions for incorporating it into your builds.

Step 1 - Install Violations Plugin

Firstly, you'll need to install the Jenkins Violations Plugin if you haven't already.

Step 2 - Run Prospector

You can run prospector with any of the normal command line options, as long as you include --output-format pylint. This will cause prospector to generate output very similar to pylint -f parseable, which is what is read by the violations plugin.

Another important flag is the --zero-exit flag. If prospector finds any problems at all, normally, then it will exit with a code of 1. This is to make automation in other circumstances easier. However, if your shell script exits in Jenkins with a non-zero exit code, Jenkins thinks it failed and therefore fails the build. Using the --zero-exit flag causes prospector to exit with a code of 0 if it succeeds in running, regardless of how many messages are found.

Include the following line somewhere in your list of CI job tasks:

prospector --zero-exit --output-format pylint > prospector.log

Like so:

Jenkins prospector task

Step 3 - Configure the Violations Plugin

Now the Violations plugin needs to be told to look at the output of prospector. Under the pylint section, add **/prospector.log to the XML filename pattern:

Violations plugin configuration

Problems

Obviously this is not a perfect solution, but it works pretty well. The only downside is that all errors reported by tools other than pylint are classifed as 'medium severity'.

Future Work

I want to add first-class prospector support to the Jenkins Violations Plugin. I'll be dusting off my Java skills in the next few weeks - it's been several years since I delved into the world of Maven and public static void main. Keep an eye on the violations plugin repository for a pull request.

People have also asked for xUnit output support. Once I figure out what that is supposed to look like, I'll add it as a new output formatter, which will hopefully allow prospector to be used in more CI tools straight away.

Feel free to sign up below for email updates if you're interested in finding out when either of these two is available.

If you enjoyed this article and would like to receive email notifications when new articles are published, sign up below:

About Landscape.io

Landscape.io is a tool to measure and track code quality and technical debt in your project. It can analyse Python code to point out errors and problems, and provides continuous metrics so you can see if your code is deteriorating.

You can sign up today with a free 14 day trial - no credit card required.

Get Started Now!