Setting up Jenkins as a watchdog for your Python application

November 2013 · 3 minute read

In order to facilitate  an efficient collaboration amongst developer teams, it is very important to keep the development workflow as simple and straightforward as possible. Version Control is one tool that helps with this. Continuous Integration is another one. Below, I’ll illustrate the steps needed to configure a basic Python application with Jenkins, a CI server that automates a lot of the repetitive stuff, so that you can focus on writing code. Well, let’s get started then.

Before we move ahead, make sure that you have Jenkins installed on your system. The installations binaries and guides are available in the official site. The CI dashboard should be visible at http://localhost:8080, if your installation was successful.

Create a new project, and fill in the *GitHub project *option with the path to your local git repository.

local-git-repo-config

 

Next, install the following plugins:

After installing the above, restart Jenkins and move on to the next step.

Once you’re done restarting, open Jenkins Dashboard > Manage Jenkins > Configure System. Set your GitHub username and email under the Git Plugin option

Now, go back to your projet configuration and set the following properties:

# Adding virtualenv to PATH
PATH=/usr/local/bin:$PATH
cd $WORKSPACE/

virtualenv --no-site-packages ve
. ve/bin/activate

# Installing necessary packages and project dependencies
pip install -r requirements.txt --download-cache=/tmp/$JOB_NAME
pip install nose
pip install coverage
pip install pylint

# Running Tests
nosetests --with-xunit --all-modules --traverse-namespace --with-coverage --cover-package=bootstrapy --cover-inclusive

# Generating code coverage
coverage xml

# Checking for pylint violations
pylint -f parseable -d I0011,R0801 mypackage | tee pylint.out

coverage-and-test-config

pylint-config

 

That’s it ! Now build your project and you should be able to get test, coverage and pylint violation reports right on the project dashboard. The best part is the fact that this is just the tip of the iceberg in terms of what Jenkins is capable of. There are lot more cooler things that you can do. So, have fun exploring !

comments powered by Disqus