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.
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' )
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:
As our project is a git repository, select the Git option in the source code management.
Set 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.
Select Add post-build action -> Publish Cobertura Coverage Report. Add cobertura report location.
Select Add post-build action -> Publish JUnit test result report. Add test result report location.
Select Add post-build action -> Report Violations. Add locations of violations reports.
Press “Build Now” and see what you’ve got:
Code coverage report.
Test result report.
Test result and code coverage graph.
Pep8 and pylint graph.
Well, this is it! I hope you liked it.