From 9b0d827d22e660e909aa65afece42b40df1cefe5 Mon Sep 17 00:00:00 2001 From: Emmanuel Cazenave Date: Wed, 27 Jun 2018 15:32:06 +0200 Subject: [PATCH] create jenkins pipeline job (#24805) --- Jenkinsfile | 39 +++++++++++++++++++++++++++++++++++++++ jenkins.sh | 25 ++++++++----------------- pylint.sh | 13 +++++++++++++ tests/settings.py | 2 +- tox.ini | 11 +++++++---- 5 files changed, 68 insertions(+), 22 deletions(-) create mode 100644 Jenkinsfile create mode 100755 pylint.sh diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..aa184886 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,39 @@ +@Library('eo-jenkins-lib@wip/publish_coverage_native') import eo.Utils + +pipeline { + agent any + stages { + stage('Unit Tests') { + steps { + sh './jenkins.sh' + } + } + stage('Packaging') { + steps { + script { + if (env.JOB_NAME == 'authentic2' && env.GIT_BRANCH == 'origin/master') { + sh 'sudo -H -u eobuilder /usr/local/bin/eobuilder -d jessie authentic' + } + } + } + } + } + post { + always { + script { + utils = new Utils() + utils.mail_notify(currentBuild, env, 'admin+jenkins-authentic@entrouvert.com') + utils.publish_coverage('coverage-*.xml') + utils.publish_coverage_native( + 'index.html', 'htmlcov-coverage-dj18-authentic-pg', 'Coverage a2') + utils.publish_coverage_native( + 'index.html', 'htmlcov-coverage-dj18-rbac-pg', , 'Coverage rbac') + utils.publish_pylint('pylint.out') + } + junit 'junit-*.xml' + } + success { + cleanWs() + } + } +} diff --git a/jenkins.sh b/jenkins.sh index d38131d4..f9eda437 100755 --- a/jenkins.sh +++ b/jenkins.sh @@ -2,20 +2,11 @@ set -e -./getlasso.sh -# SNI support for Debian -pip install --upgrade pyOpenSSL ndg-httpsclient pyasn1 -pip install --upgrade pip\>9 -pip install --upgrade pylint pylint-django 'django<1.9' -pip install --upgrade tox -pip install -U 'virtualenv<14' -rm -f coverage*.xml junit*.xml -if [[ `date +%H%M` < 630 ]]; then - # run full tests (with migrations) at night - tox -r -e 'coverage-dj18-{authentic,rbac}-{pg,sqlite}' -else - tox -r -e 'fast-coverage-dj18-{authentic,rbac}-{pg,sqlite}' -fi -(pylint -f parseable --rcfile /var/lib/jenkins/pylint.django.rc src/authentic2/ | tee pylint.out) || /bin/true -./merge-junit-results.py junit-*coverage-dj18-authentic-pg.xml junit-*coverage-dj18-rbac-pg.xml > junit.xml -./merge-coverage.py -o coverage.xml coverage-*.xml +for DIRECTORY in "htmlcov" "htmlcov-coverage-dj18-authentic-pg" "htmlcov-coverage-dj18-rbac-pg" +do + if [ -d "$DIRECTORY" ]; then + rm -r $DIRECTORY + fi +done + +tox -rv diff --git a/pylint.sh b/pylint.sh new file mode 100755 index 00000000..d7295ccf --- /dev/null +++ b/pylint.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e -x +env +if [ -f /var/lib/jenkins/pylint.django.rc ]; then + PYLINT_RC=/var/lib/jenkins/pylint.django.rc +elif [ -f pylint.django.rc ]; then + PYLINT_RC=pylint.django.rc +else + echo No pylint RC found + exit 0 +fi +pylint -f parseable --rcfile ${PYLINT_RC} "$@" | tee pylint.out || /bin/true diff --git a/tests/settings.py b/tests/settings.py index bdde5b7d..fb04caea 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -13,7 +13,7 @@ DATABASES = { 'default': { 'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.sqlite3'), 'TEST': { - 'NAME': 'a2-test', + 'NAME': 'a2-test-%s' % os.environ.get("BRANCH_NAME", "").replace('/', '-'), }, } } diff --git a/tox.ini b/tox.ini index cade4a42..dc0dcfb9 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/authentic/ +toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/combo/{env:BRANCH_NAME:} envlist = coverage-dj18-{authentic,rbac}-{pg,sqlite} [testenv] @@ -13,9 +13,10 @@ whitelist_externals = /bin/mv setenv = AUTHENTIC2_SETTINGS_FILE=tests/settings.py + BRANCH_NAME={env:BRANCH_NAME:} sqlite: DB_ENGINE=django.db.backends.sqlite3 pg: DB_ENGINE=django.db.backends.postgresql_psycopg2 - coverage: COVERAGE=--junitxml=junit-{envname}.xml --cov-report xml --cov=src/ --cov-config .coveragerc + coverage: COVERAGE=--junitxml=junit-{envname}.xml --cov-report xml --cov-report html --cov=src/ --cov-config .coveragerc authentic: DJANGO_SETTINGS_MODULE=authentic2.settings rbac: DJANGO_SETTINGS_MODULE=django_rbac.test_settings fast: FAST=--nomigrations @@ -25,7 +26,6 @@ usedevelop = deps = pip > 9 dj18: django>1.8,<1.9 - dj19: django>1.8,<1.9 pg: psycopg2 coverage pytest-cov @@ -45,8 +45,11 @@ deps = commands = ./getlasso.sh authentic: py.test {env:FAST:} {env:COVERAGE:} {posargs:tests/ --random} - rbac: py.test --nomigrations {env:COVERAGE:} {posargs:tests_rbac/} + rbac: py.test {env:FAST:} {env:COVERAGE:} {posargs:tests_rbac/} coverage: mv coverage.xml coverage-{envname}.xml + coverage-dj18-authentic-pg: mv htmlcov htmlcov-coverage-dj18-authentic-pg + coverage-dj18-rbac-pg: mv htmlcov htmlcov-coverage-dj18-rbac-pg + coverage-dj18-authentic-pg: ./pylint.sh src/authentic2/ [testenv:check] -- 2.18.0