Continuous integration of Django projects with Jenkins
Jenkins is a tool for watching or managing jobs. Either external like cronjobs or executing "build and test" jobs of your Django projects. There is even more, but in this article I'll focus on a basic Jenkins setup - building and testing a Django project. For Django there is django-jenkins that allows an easy integration with Jenkins tools like nice visualization of code coverage, pep8/pylint/pyflakes code violations.
In this article I'll setup a local Jenkins configuration that will look on a folder with the code. In real world Jenkins would watch a repository and execute a job when a new changeset shows up.
Jenkins
On Jenkins web page we can find packages for various OS. We can also download a WAR file for local execution (you will need a JAVA JRE and maybe few other dependencies).
- Download the WAR file.
- From a terminal launch it with
java -jar jenkins.war
- Jenkins will start and will be available at http://localhost:8080/

Jenkins after start with my first job configuration

Plugin instalation in Jenkins
Creating a job for a Django project
Click on "New" and create new job. Enter a name and choose "Build a free-style software project". If you already have a similar job you can copy it too.
Adding a new job in Jenkins

Enter a path to a folder with a Django project

Build triggers configuration

Build instructions

Code coverage reports configuration

Test execution configuration

Violations plugin configuration
Django-Jenkins
We can install it the usual way:JENKINS_TASKS = (
'django_jenkins.tasks.with_coverage',
'django_jenkins.tasks.django_tests',
'django_jenkins.tasks.run_pep8',
'django_jenkins.tasks.run_pyflakes',
)
By default tests of Django and everything in INSTALLED_APPS will be launched. That's not the best thing for the reports. We can define PROJECT_APPS that will hold a list of our apps for for testing. For example:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'javascript_settings',
'django_jenkins'
)
PROJECT_APPS = (
'jsdemo',
'testapp',
)
INSTALLED_APPS += PROJECT_APPS
What Jenkins can tell us?

A list of builds of a Jenkins job
- Console: log from the executed tasks. Sometimes it may fail at downloading packages from pypi. You can retrigger a task to repeat it when pypi is online again.
- Coverage Report: reports about code coverage with visualization of branches/conditionals coverage.
- Violations: This will cover pep8, pylint/pyflakes violations.




You will find more info on django-jenkins Tutorial and Continuous Integration with Jenkins.
Comment article