Featured Image
Software Development

django-jenkins integration for Django project

In this tutorial, we will see a demonstration of how to integrate a django-jenkins for Django project.

Configuring Django project

To use django-jenkins you need to install it by running below command.

Pip install django-jenkins

After installation, you need to add django_jenkins to INSTALLED_APPS in settings.py.

Running

python manage.py jenkins

will do the same job as

python manage.py test

but also will create reports folder in the root of your Django project with jenkins parsable pylint, test coverage and tests reports.

Django-jenkins have support for several other testing tools/ To enable it, you should include tools task to JENKINS_TASKS settings variable in the settings.py.

JENKINS_TASKS = (
    'django_jenkins.tasks.run_pep8',
    'django_jenkins.tasks.run_pyflakes',
    'django_jenkins.tasks.run_jslint',
    'django_jenkins.tasks.run_csslint',
    'django_jenkins.tasks.run_sloccount'
)

Configuring jenkins

You need to install three required plugins:

  • Violations plugin for parsing pylint reports.
  • Cobertura plugin for showing the code coverage.
  • Git plugin for source code management.

Install these plugins from Manage Jenkins -> Manage Plugins -> Available.

Start a new job with creating a free-style project via New Item:

Create new free style project

Create new free style project

As our project is a git repository, select the Git option in the source code management.

Source code management

Source code management

Set build triggers.

Build triggers

Build triggers

I choose to poll the repository on every hour. If there is a change, Jenkins will download it and do the tests.

Select Add build step -> Execute shell. Add commands to setup environment and the run tests command.

Execute shell

Execute shell

Select Add post-build action -> Publish Cobertura Coverage Report. Add cobertura report location.

Cobertura coverage report

Cobertura coverage report

Select Add post-build action -> Publish JUnit test result report. Add test result report location.

JUnit test result report

JUnit test result report

Select Add post-build action -> Report Violations. Add locations of violations reports.

Report violations

Report violations

Results:

Press “Build Now” and see what you’ve got:

Code coverage report.

Code coverage report

Code coverage report

Test result report.

Test result report

Test result report

Test result and code coverage graph.

Test result and code coverage graph

Test result and code coverage graph

Pep8 and pylint graph.

Pep8 and pylint graph

Pep8 and pylint graph

Finished…..:)

Also read: Enhancing Django Admin Panel Security with Two-Factor Authentication (2FA)

author
Nensi Trambadiya