Jenkinsfile
211 lines
| 8.7 KiB
| text/plain
|
TextLexer
domruf
|
r6536 | def createvirtualenv = '' | ||
def activatevirtualenv = '' | ||||
domruf
|
r6496 | node { | ||
domruf
|
r6850 | properties([[$class: 'BuildDiscarderProperty', | ||
strategy: [$class: 'LogRotator', | ||||
artifactDaysToKeepStr: '', | ||||
artifactNumToKeepStr: '10', | ||||
daysToKeepStr: '', | ||||
numToKeepStr: '']]]); | ||||
domruf
|
r6496 | if (isUnix()) { | ||
Mads Kiilerich
|
r8073 | createvirtualenv = 'rm -r $JENKINS_HOME/venv/$JOB_NAME || true && python3 -m venv $JENKINS_HOME/venv/$JOB_NAME' | ||
domruf
|
r6505 | activatevirtualenv = '. $JENKINS_HOME/venv/$JOB_NAME/bin/activate' | ||
domruf
|
r6496 | } else { | ||
Mads Kiilerich
|
r8073 | createvirtualenv = 'rmdir /s /q %JENKINS_HOME%\\venv\\%JOB_NAME% || true && python3 -m venv %JENKINS_HOME%\\venv\\%JOB_NAME%' | ||
domruf
|
r6505 | activatevirtualenv = 'call %JENKINS_HOME%\\venv\\%JOB_NAME%\\Scripts\\activate.bat' | ||
domruf
|
r6496 | } | ||
stage('checkout') { | ||||
checkout scm | ||||
if (isUnix()) { | ||||
sh 'hg --config extensions.purge= purge --all' | ||||
} else { | ||||
bat 'hg --config extensions.purge= purge --all' | ||||
} | ||||
} | ||||
stage('virtual env') { | ||||
domruf
|
r6505 | def virtualenvscript = """$createvirtualenv | ||
domruf
|
r6496 | $activatevirtualenv | ||
python -m pip install --upgrade pip | ||||
Mads Kiilerich
|
r8767 | pip install --upgrade "setuptools<67" | ||
domruf
|
r6496 | pip install --upgrade pylint | ||
pip install --upgrade pytest-cov | ||||
""" | ||||
if (isUnix()) { | ||||
virtualenvscript += """ | ||||
pip install --upgrade python-ldap | ||||
pip install --upgrade python-pam | ||||
""" | ||||
sh virtualenvscript | ||||
} else { | ||||
bat virtualenvscript | ||||
} | ||||
} | ||||
stage('setup') { | ||||
def virtualenvscript = """$activatevirtualenv | ||||
Mads Kiilerich
|
r7747 | pip install --upgrade -e . -r dev_requirements.txt | ||
domruf
|
r6496 | python setup.py compile_catalog | ||
""" | ||||
if (isUnix()) { | ||||
sh virtualenvscript | ||||
} else { | ||||
bat virtualenvscript | ||||
} | ||||
stash name: 'kallithea', useDefaultExcludes: false | ||||
} | ||||
stage('pylint') { | ||||
sh script: """$activatevirtualenv | ||||
pylint -j 0 --disable=C -f parseable kallithea > pylint.out | ||||
""", returnStatus: true | ||||
archiveArtifacts 'pylint.out' | ||||
try { | ||||
step([$class: 'WarningsPublisher', canComputeNew: false, canResolveRelativePaths: false, defaultEncoding: '', excludePattern: '', healthy: '', includePattern: '', messagesPattern: '', parserConfigurations: [[parserName: 'PyLint', pattern: 'pylint.out']], unHealthy: '']) | ||||
domruf
|
r6506 | } catch (java.lang.IllegalArgumentException exc) { | ||
domruf
|
r6496 | echo "You need to install the 'Warnings Plug-in' to display the pylint report." | ||
currentBuild.result = 'UNSTABLE' | ||||
echo "Caught: ${exc}" | ||||
} | ||||
} | ||||
domruf
|
r6536 | } | ||
def pytests = [:] | ||||
pytests['sqlite'] = { | ||||
node { | ||||
domruf
|
r6496 | ws { | ||
domruf
|
r6507 | deleteDir() | ||
domruf
|
r6496 | unstash name: 'kallithea' | ||
if (isUnix()) { | ||||
sh script: """$activatevirtualenv | ||||
domruf
|
r6849 | py.test -p no:sugar --cov-config .coveragerc --junit-xml=pytest_sqlite.xml --cov=kallithea | ||
domruf
|
r6496 | """, returnStatus: true | ||
} else { | ||||
bat script: """$activatevirtualenv | ||||
domruf
|
r6849 | py.test -p no:sugar --cov-config .coveragerc --junit-xml=pytest_sqlite.xml --cov=kallithea | ||
domruf
|
r6496 | """, returnStatus: true | ||
} | ||||
sh 'sed --in-place "s/\\(classname=[\'\\"]\\)/\\1SQLITE./g" pytest_sqlite.xml' | ||||
archiveArtifacts 'pytest_sqlite.xml' | ||||
junit 'pytest_sqlite.xml' | ||||
domruf
|
r6849 | writeFile(file: '.coverage.sqlite', text: readFile('.coverage')) | ||
stash name: 'coverage.sqlite', includes: '.coverage.sqlite' | ||||
domruf
|
r6496 | } | ||
} | ||||
domruf
|
r6536 | } | ||
pytests['de'] = { | ||||
node { | ||||
if (isUnix()) { | ||||
domruf
|
r6496 | ws { | ||
domruf
|
r6507 | deleteDir() | ||
domruf
|
r6496 | unstash name: 'kallithea' | ||
withEnv(['LANG=de_DE.UTF-8', | ||||
'LANGUAGE=de', | ||||
'LC_ADDRESS=de_DE.UTF-8', | ||||
'LC_IDENTIFICATION=de_DE.UTF-8', | ||||
'LC_MEASUREMENT=de_DE.UTF-8', | ||||
'LC_MONETARY=de_DE.UTF-8', | ||||
'LC_NAME=de_DE.UTF-8', | ||||
'LC_NUMERIC=de_DE.UTF-8', | ||||
'LC_PAPER=de_DE.UTF-8', | ||||
'LC_TELEPHONE=de_DE.UTF-8', | ||||
'LC_TIME=de_DE.UTF-8', | ||||
]) { | ||||
sh script: """$activatevirtualenv | ||||
domruf
|
r6849 | py.test -p no:sugar --cov-config .coveragerc --junit-xml=pytest_de.xml --cov=kallithea | ||
domruf
|
r6496 | """, returnStatus: true | ||
} | ||||
sh 'sed --in-place "s/\\(classname=[\'\\"]\\)/\\1DE./g" pytest_de.xml' | ||||
archiveArtifacts 'pytest_de.xml' | ||||
junit 'pytest_de.xml' | ||||
domruf
|
r6849 | writeFile(file: '.coverage.de', text: readFile('.coverage')) | ||
stash name: 'coverage.de', includes: '.coverage.de' | ||||
domruf
|
r6496 | } | ||
} | ||||
domruf
|
r6536 | } | ||
} | ||||
pytests['mysql'] = { | ||||
node { | ||||
if (isUnix()) { | ||||
domruf
|
r6496 | ws { | ||
domruf
|
r6507 | deleteDir() | ||
domruf
|
r6496 | unstash name: 'kallithea' | ||
sh """$activatevirtualenv | ||||
pip install --upgrade MySQL-python | ||||
""" | ||||
withEnv(['TEST_DB=mysql://kallithea:kallithea@jenkins_mysql/kallithea_test?charset=utf8']) { | ||||
if (isUnix()) { | ||||
sh script: """$activatevirtualenv | ||||
domruf
|
r6849 | py.test -p no:sugar --cov-config .coveragerc --junit-xml=pytest_mysql.xml --cov=kallithea | ||
domruf
|
r6496 | """, returnStatus: true | ||
} else { | ||||
bat script: """$activatevirtualenv | ||||
domruf
|
r6849 | py.test -p no:sugar --cov-config .coveragerc --junit-xml=pytest_mysql.xml --cov=kallithea | ||
domruf
|
r6496 | """, returnStatus: true | ||
} | ||||
} | ||||
sh 'sed --in-place "s/\\(classname=[\'\\"]\\)/\\1MYSQL./g" pytest_mysql.xml' | ||||
archiveArtifacts 'pytest_mysql.xml' | ||||
junit 'pytest_mysql.xml' | ||||
domruf
|
r6849 | writeFile(file: '.coverage.mysql', text: readFile('.coverage')) | ||
stash name: 'coverage.mysql', includes: '.coverage.mysql' | ||||
domruf
|
r6496 | } | ||
} | ||||
domruf
|
r6536 | } | ||
} | ||||
pytests['postgresql'] = { | ||||
node { | ||||
if (isUnix()) { | ||||
domruf
|
r6496 | ws { | ||
domruf
|
r6507 | deleteDir() | ||
domruf
|
r6496 | unstash name: 'kallithea' | ||
sh """$activatevirtualenv | ||||
pip install --upgrade psycopg2 | ||||
""" | ||||
withEnv(['TEST_DB=postgresql://kallithea:kallithea@jenkins_postgresql/kallithea_test']) { | ||||
if (isUnix()) { | ||||
sh script: """$activatevirtualenv | ||||
domruf
|
r6849 | py.test -p no:sugar --cov-config .coveragerc --junit-xml=pytest_postgresql.xml --cov=kallithea | ||
domruf
|
r6496 | """, returnStatus: true | ||
} else { | ||||
bat script: """$activatevirtualenv | ||||
domruf
|
r6849 | py.test -p no:sugar --cov-config .coveragerc --junit-xml=pytest_postgresql.xml --cov=kallithea | ||
domruf
|
r6496 | """, returnStatus: true | ||
} | ||||
} | ||||
sh 'sed --in-place "s/\\(classname=[\'\\"]\\)/\\1POSTGRES./g" pytest_postgresql.xml' | ||||
archiveArtifacts 'pytest_postgresql.xml' | ||||
junit 'pytest_postgresql.xml' | ||||
domruf
|
r6849 | writeFile(file: '.coverage.postgresql', text: readFile('.coverage')) | ||
stash name: 'coverage.postgresql', includes: '.coverage.postgresql' | ||||
domruf
|
r6496 | } | ||
} | ||||
} | ||||
} | ||||
domruf
|
r6536 | stage('Tests') { | ||
parallel pytests | ||||
domruf
|
r6849 | node { | ||
unstash 'coverage.sqlite' | ||||
unstash 'coverage.de' | ||||
unstash 'coverage.mysql' | ||||
unstash 'coverage.postgresql' | ||||
if (isUnix()) { | ||||
sh script: """$activatevirtualenv | ||||
coverage combine .coverage.sqlite .coverage.de .coverage.mysql .coverage.postgresql | ||||
coverage xml | ||||
""", returnStatus: true | ||||
} else { | ||||
bat script: """$activatevirtualenv | ||||
coverage combine .coverage.sqlite .coverage.de .coverage.mysql .coverage.postgresql | ||||
coverage xml | ||||
""", returnStatus: true | ||||
} | ||||
try { | ||||
step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: 'coverage.xml', failNoReports: false, failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, onlyStable: false, zoomCoverageChart: false]) | ||||
} catch (java.lang.IllegalArgumentException exc) { | ||||
echo "You need to install the pipeline compatible 'CoberturaPublisher Plug-in' to display the coverage report." | ||||
currentBuild.result = 'UNSTABLE' | ||||
echo "Caught: ${exc}" | ||||
} | ||||
} | ||||
domruf
|
r6536 | } | ||