Jenkinsfile: use TMPDIR and pg_virtualenv (#31750)

This commit is contained in:
Benjamin Dauvergne 2019-05-10 11:26:40 +02:00
parent 392c22c2be
commit 6aeef35e26
3 changed files with 24 additions and 2 deletions

11
Jenkinsfile vendored
View File

@ -3,10 +3,18 @@
pipeline {
agent any
options { disableConcurrentBuilds() }
environment {
TMPDIR = "/tmp/$BUILD_TAG"
}
stages {
stage('Unit Tests') {
steps {
sh 'tox -rv'
sh "mkdir ${env.TMPDIR}"
sh """
virtualenv -p python3 ${env.TMPDIR}/venv/
. ${env.TMPDIR}/venv/bin/activate
${env.TMPDIR}/venv/bin/pip install tox
PGPORT=`python -c 'import struct; import socket; s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'` pg_virtualenv -o fsync=off ${env.TMPDIR}/venv/bin/tox -rv"""
}
post {
always {
@ -39,6 +47,7 @@ pipeline {
}
}
success {
sh "rm -rf ${env.TMPDIR}"
cleanWs()
}
}

View File

@ -9,3 +9,8 @@ DATABASES = {
},
}
}
if 'postgres' in DATABASES['default']['ENGINE']:
for key in ('PGPORT', 'PGHOST', 'PGUSER', 'PGPASSWORD'):
if key in os.environ:
DATABASES['default'][key[2:]] = os.environ[key]

10
tox.ini
View File

@ -17,7 +17,15 @@ setenv =
DJANGO_SETTINGS_MODULE=authentic2.settings
sqlite: DB_ENGINE=sqlite3
pg: DB_ENGINE=postgresql_psycopg2
JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml}
coverage: COVERAGE=--cov=src --cov-branch --cov-append --cov-report xml --cov-report html
# support for pg_virtualenv
PGPORT={env:PGPORT:}
PGHOST={env:PGHOST:}
PGUSER={env:PGUSER:}
PGPASSWORD={env:PGPASSWORD:}
usedevelop =
coverage: true
deps =
@ -36,7 +44,7 @@ deps =
oldldap: python-ldap<3
commands =
./getlasso.sh
py.test {env:COVERAGE:} -o junit_suite_name={envname} --junit-xml=junit-{envname}.xml {posargs:tests}
py.test {env:COVERAGE:} {env:JUNIT:} {posargs:tests}
[testenv:pylint]
basepython = python2.7