From 602ae3c596df4d1306594d5da37a17628b79a1d2 Mon Sep 17 00:00:00 2001 From: INOPIAE Date: Tue, 15 Sep 2020 13:40:01 +0200 Subject: [PATCH] add: configuration for Jenkins Change-Id: Ie9deac0d0e0a61fe85964e1d9c9158f69322b521 --- README.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ jenkins_job.py | 13 +++++++++ requirements.txt | 1 + 3 files changed, 90 insertions(+) create mode 100644 jenkins_job.py diff --git a/README.md b/README.md index 6b2618d..4681fba 100644 --- a/README.md +++ b/README.md @@ -103,3 +103,79 @@ fastcgi_param USER_ROLES $motion_user_role; fastcgi_pass unix:/motion-socket/motion.fcgi; } ``` + +# Configuration for a Jenkins Freestyle Project + +## Preconditions for Jenkins system + +* Python 3 installed with: + + python3 virtualenv python3-pip + +* PostgreSQL server installed with motion database and database user + + +## Add freestyle project + +### Source-Code-Management + +Adjust Git settings + +### Build Environment + +Add Bindings + +Add Username and password (separated) + +Enter username (DB_USER) and password (DB_PW) according to database credentials + +### Build + +Add build step shell + +Add the command + +``` +rm -rf env +virtualenv -p python3 env +. env/bin/activate +pip3 install -r requirements.txt + + +cat > config.py << EOF +DATABASE="pq://IP-ADDRESS/motion" +USER="${DB_USER}" +PASSWORD="${DB_PW}" +EOF + +python3 jenkins_job.py +``` + +If an IPv6 address is used the following needs to be added to the script to fix a bug of the IPv6 literal translation: +(https://github.com/python-postgres/fe/issues/104) + +``` +patch env/lib/python3*/site-packages/postgresql/versionstring.py < ( + Split a PostgreSQL version string into a tuple + (major,minor,patch,...,state_class,state_level) + """ +- v = vstr.strip().split('.') ++ v = vstr.strip().split(' ')[0].split('.') + + # Get rid of the numbers around the state_class (beta,a,dev,alpha, etc) + state_class = v[-1].strip('0123456789') +EOF +``` + +### Post build actions + +Add Publish JUnit test result report - test report XMLs + +``` +python_tests_xml/* +``` diff --git a/jenkins_job.py b/jenkins_job.py new file mode 100644 index 0000000..56dc831 --- /dev/null +++ b/jenkins_job.py @@ -0,0 +1,13 @@ +import unittest +import xmlrunner + +def runner(output='python_tests_xml'): + return xmlrunner.XMLTestRunner( + output=output + ) + +def find_tests(): + return unittest.TestLoader().discover('tests', 'test_motion.py') + +if __name__ == "__main__": + runner().run(find_tests()) diff --git a/requirements.txt b/requirements.txt index 7bfcb1f..0713e61 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ MarkupSafe==1.0 py-postgresql==1.2.1 Werkzeug==0.12.2 Flask-Markdown==0.3 +xmlrunner>=1.7.7 -- 2.39.2