Setting up McCabe Code Complexity reporting for Python in Jenkins (Hudson)

In this post I’m going to explain the steps in order to integrate pycabehtml https://bitbucket.org/jordilin/pycabehtml  into Jenkins using the Html Plugin.

  1. Add build step Execute Shell.
  2. You’ll see a text box where you will be able to write the shell script that will be executed in order to build your project and obtain metrics.
  3. Write the following in the text box.
cd $WORKSPACE
COMPLEXITY_DIR=$WORKSPACE/complexity
GRAPH=$COMPLEXITY_DIR/output.png
ACC=/usr/local/jenkins/jenkinsprojectname/complexity_acc.txt
mkdir -p $COMPLEXITY_DIR
pymetrics `find yoursrc/ -iname "*.py"` > $COMPLEXITY_DIR/complexity.txt
pycabehtml.py -i $COMPLEXITY_DIR/complexty.txt -o $COMPLEXITY_DIR/metrics.html -a $ACC -g $GRAPH

4. You can save this script into a shell script and put it under source control (recommended), and then execute this shell script from the jenkins build step execute shell.

5. Enable the Html plugin for Jenkins

Advertisements

About jordilin

I'm a Senior Software Engineer with an MSc in Telecommunications Engineering. I've got a range of interests including Linux, a very powerful and limitless operating system, travelling, gastronomy and technology.
This entry was posted in Continuous Integration, Jenkins, Python and tagged , , , , , . Bookmark the permalink.

3 Responses to Setting up McCabe Code Complexity reporting for Python in Jenkins (Hudson)

  1. Yah, so can you believe it?!?!?! I can’t wait!!!!!!!! Click http://d2.ae/hool090645

  2. This is a great way to show McCabe results in Jenkins. I wish this was a plugin!

  3. grayaii says:

    I could not get this to work on centos with python 2.7. Since pymetrics does not exist for centos, I did “git clone https://github.com/ipmb/PyMetrics.git“, ran it against a dummy python file, and then ran (I removed ACC since I didn’t see how that file was being generated):
    “`
    pycabehtml -i /mnt/ope/ws/workspace/_alex/complexity/complexity.txt -o /mnt/ope/ws/workspace/_alex/complexity/metrics.html -g /mnt/ope/ws/workspace/_alex/complexity/output.png
    Traceback (most recent call last):
    File “/mnt/ope/ws/workspace/_alex/build/bin/pycabehtml”, line 11, in
    load_entry_point(‘pycabehtml==0.14’, ‘console_scripts’, ‘pycabehtml’)()
    File “/mnt/ope/ws/workspace/_alex/build/local/lib/python2.7/site-packages/pycabehtml-0.14-py2.7.egg/EGG-INFO/scripts/pycabehtml.py”, line 108, in main

    File “/mnt/ope/ws/workspace/_alex/build/local/lib/python2.7/site-packages/pycabehtml-0.14-py2.7.egg/EGG-INFO/scripts/pycabehtml.py”, line 82, in report_complexity

    File “/mnt/ope/ws/workspace/_alex/build/lib64/python2.7/posixpath.py”, line 122, in dirname
    i = p.rfind(‘/’) + 1
    “`

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s