dosage/Jenkinsfile

141 lines
4.4 KiB
Text
Raw Normal View History

def pys = [
2020-10-06 23:11:58 +00:00
[name: 'Python 3.9', docker:'python:3.9-buster', tox:'py39', main: false],
[name: 'Python 3.8', docker:'python:3.8-buster', tox:'py38,flake8', main: true],
[name: 'Python 3.7', docker:'python:3.7-buster', tox:'py37', main: false],
[name: 'Python 3.6', docker:'python:3.6-buster', tox:'py36', main: false],
[name: 'Python 3.5', docker:'python:3.5-buster', tox:'py35', main: false],
]
properties([
durabilityHint('PERFORMANCE_OPTIMIZED'),
2020-04-11 09:43:29 +00:00
buildDiscarder(logRotator(numToKeepStr: '100')),
])
Map tasks = [failFast: true]
pys.each { py ->
tasks[py.name] = {
node {
def image
stage("Prepare docker $py.name") {
dir('dockerbuild') {
deleteDir()
docker.image(py.docker).pull()
buildDockerfile(py.docker)
image = docker.build("dosage-$py.docker")
}
}
stage("Build $py.name") {
image.inside {
checkout scm
sh '''
git clean -fdx
git fetch --tags
'''
2019-07-14 10:57:06 +00:00
warnError('tox failed') {
sh "tox -e $py.tox"
}
if (py.main) {
sh """
python setup.py sdist bdist_wheel
"""
}
}
if (py.main) {
archiveArtifacts artifacts: 'dist/*', fingerprint: true
2018-05-13 22:50:45 +00:00
stash includes: 'dist/*.tar.gz', name: 'bin'
2020-11-22 22:25:11 +00:00
dir('.tox') {
stash includes: 'allure-*/**', name: 'allure'
}
def buildVer = findFiles(glob: 'dist/*.tar.gz')[0].name.replaceFirst(/\.tar\.gz$/, '')
currentBuild.description = buildVer
2019-10-28 15:15:26 +00:00
publishCoverage calculateDiffForChangeRequests: true,
sourceFileResolver: sourceFiles('STORE_LAST_BUILD'),
adapters: [
coberturaAdapter('.tox/cov-*.xml')
]
2019-07-14 11:12:03 +00:00
recordIssues sourceCodeEncoding: 'UTF-8',
referenceJobName: 'dosage/master',
2019-07-14 11:12:03 +00:00
tool: flake8(pattern: '.tox/flake8.log', reportEncoding: 'UTF-8')
}
junit '.tox/junit-*.xml'
}
}
}
}
// MAIN //
parallel(tasks)
stage('Windows binary') {
windowsBuild()
}
stage('Allure report') {
processAllure()
}
def buildDockerfile(image) {
def uid = sh(returnStdout: true, script: 'id -u').trim()
writeFile file: 'Dockerfile', text: """
FROM $image
RUN pip install tox
RUN useradd -mu $uid dockerjenkins
"""
}
2018-05-13 22:50:45 +00:00
def windowsBuild() {
2020-11-22 22:25:11 +00:00
warnError('windows build failed') {
node {
windowsBuildCommands()
2018-05-13 22:50:45 +00:00
}
}
}
def windowsBuildCommands() {
deleteDir()
unstash 'bin'
// Keep 3.8 for now, so we are still compatible with Windows 7
def img = docker.image('tobix/pywine:3.8')
img.pull()
img.inside {
sh '''
. /opt/mkuserwineprefix
tar xvf dist/dosage-*.tar.gz
cd dosage-*
xvfb-run sh -c "
wine py -m pip install -e .[css] &&
cd scripts &&
wine py -m PyInstaller -y dosage.spec;
wineserver -w" 2>&1 | tee log.txt
'''
archiveArtifacts '*/scripts/dist/*'
}
}
2020-11-22 22:25:11 +00:00
def processAllure() {
warnError('allure report failed') {
node {
deleteDir()
unstash 'allure'
sh 'mv allure-* allure-data'
copyArtifacts filter: 'allure-history.zip', optional: true, projectName: JOB_NAME, selector: lastWithArtifacts()
if (fileExists('allure-history.zip')) {
unzip dir: 'allure-data', quiet: true, zipFile: 'allure-history.zip'
sh 'rm -f allure-history.zip'
}
sh 'docker run --rm -v $PWD:/work -u $(id -u) tobix/allure-cli generate allure-data'
2020-11-26 23:00:11 +00:00
zip archive: true, dir: 'allure-report', glob: 'history/**', zipFile: 'allure-history.zip'
2020-11-22 22:25:11 +00:00
publishHTML reportDir: 'allure-report', reportFiles: 'index.html', reportName: 'Allure Report'
}
}
}
// vim: set ft=groovy: