Hello.
A significant time in our project used a self-written integration testing system - checking the hook code in the version control system, running the tests with the support of code coverage reports, recording the results into a separate html file that was available to developers via the web. Naturally, then I had to do support for the locks so that two tests would not start at the same time, etc.
In the end, a tangible part of the working time began to go to support it, which long ago nullified all the advantages of the ease of developing such a system, and it was decided to establish a normal
Continuous Integration server.
')
Jenkins was chosen as the new system, its installation and configuration for the django project will be discussed in this article. Who are interested, welcome under cat.
Installing Jenkins
In the case of
Ubuntu, add the key and source (source) for installing packages:
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - vi /etc/apt/sources
In the case of other OS look here:
https://wiki.jenkins-ci.org/display/JENKINS/Installing+JenkinsThen:
apt-get update apt-get install jenkins
After installation,
Jenkins will start and listen on connections on port 8080, in order to change the port, you should edit the
HTTP_PORT variable (and other variables if necessary) in the
/ etc / default / jenkins file
Installing plugins
Jenkins is installed and working, now you can install the necessary plug-ins.
Go to the
Manage Jenkins menu
-> Manage Plugins , the
Available tab. Choose the plugins we need:
- Cobertura Plugin (Code Coverage)
- Violations Plugin (Code Reports - pylint, pyflakes, pep8)
- Git / Mercurial / SVN Plugin - who uses what, since we use Git, then on the screenshots the options for the GIT Plugin will be shown.
Django jenkins
To integrate django tests with the Jenkins server, we will use the django-jenkins package (By the way, its author,
kmmbvnr , is on the habr, I say hello!). The package generates reports in xml-format for all executed tests, plus generates reports of static code analyzers. These reports are then processed by the Jenkins server itself.
Installation:
pip install django-jenkins pip install pep8 pip install pyflakes
Add settings for our django project:
INSTALLED_APPS += ('django_jenkins',) JENKINS_TASKS = ('django_jenkins.tasks.run_pylint', 'django_jenkins.tasks.run_pep8', 'django_jenkins.tasks.run_pyflakes', 'django_jenkins.tasks.with_coverage', 'django_jenkins.tasks.django_tests',)
Now we have the
manage.py jenkins command , which will run the tests and generate reports for Jenkins. Now you can try to run it to see that everything works without errors. If successful, a
build directory with reports should be created.
Jenkins setup
This part of the article is a slightly revised original guide to django-jenkins:
https://sites.google.com/site/kmmbvnr/home/django-hudson-tutorialSo, create a new project: New Job -> Build a free-style software project

Configuring interaction with SCM:

When specifying a
repository browser, Jenkins will display links to the
revision diff file when viewing the list of changes in the assembly.
We configure the SCM check for changes every half hour:

Add the execution of the command from django-jenkins ( Add build step -> execute shell ):

Select Publish Cobertura Coverage Report and set the path to the report:

Select Publish JUnit test result report and also set the path to the reports:

Select Report Violations and again set the paths to the reports:


Set up email notifications if required:

Selenium test integration
To be able to run Selenium tests in Jenkins, if any, I added
JenkinsTestRunner class to the
django-selenium library, which I wrote about in my
previous article .
results
Everything is set up, you can click on
Build Now and enjoy the results:


And then do the correction of errors.
Thanks for attention.