Article

django-jenkins integration for Django project

Last updated 
Jan 19, 2019
 min read

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.

1JENKINS_TASKS = (
2    'django_jenkins.tasks.run_pep8',
3    'django_jenkins.tasks.run_pyflakes',
4    'django_jenkins.tasks.run_jslint',
5    'django_jenkins.tasks.run_csslint',
6    'django_jenkins.tasks.run_sloccount'
7)

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)

Authors

Nensi Trambadiya

Software Engineer
I’m a Software Engineer with a passion for problem-solving and building efficient, high-performing systems. I specialize in creating reliable, user-centric software that meets both technical and business needs. I’m always exploring new tools and techniques to stay ahead in an ever-evolving tech landscape.

Tags

No items found.

Have a project in mind?

Read