diff --git a/Jenkinsfile b/Jenkinsfile index 2d9665a4e..693ebb6b1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -371,35 +371,71 @@ def testPythonPackages(){ SUPPORTED_WINDOWS_VERSIONS.each{ pythonVersion -> if(params.INCLUDE_WINDOWS_X86_64 == true){ windowsTests["Windows - Python ${pythonVersion}-x86: sdist"] = { - packages.testPkg2( + packages.testPkg( agent: [ dockerfile: [ label: 'windows && docker && x86', filename: 'ci/docker/python/windows/tox/Dockerfile', - additionalBuildArgs: '--build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL --build-arg CHOCOLATEY_SOURCE', - args: '-v pipcache_speedwagon:c:/users/containeradministrator/appdata/local/pip' + additionalBuildArgs: '--build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL --build-arg CHOCOLATEY_SOURCE' ] ], - glob: 'dist/*.tar.gz,dist/*.zip', - stash: 'PYTHON_PACKAGES', - toxEnv: "py${pythonVersion.replace('.', '')}-PySide6", - retry: 3, + retries: 3, + testSetup: { + checkout scm + unstash 'PYTHON_PACKAGES' + }, + testCommand: { + findFiles(glob: 'dist/*.tar.gz,dist/*.zip').each{ + powershell(label: 'Running Tox', script: "tox --installpkg ${it.path} --workdir \$env:TEMP\\tox -e py${pythonVersion.replace('.', '')}-PySide6") + } + + }, + post:[ + cleanup: { + cleanWs( + patterns: [ + [pattern: 'dist/', type: 'INCLUDE'], + [pattern: '**/__pycache__/', type: 'INCLUDE'], + ], + notFailBuild: true, + deleteDirs: true + ) + }, + ] ) } windowsTests["Windows - Python ${pythonVersion}-x86: wheel"] = { - packages.testPkg2( + packages.testPkg( agent: [ dockerfile: [ label: 'windows && docker && x86', filename: 'ci/docker/python/windows/tox/Dockerfile', - additionalBuildArgs: '--build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL --build-arg CHOCOLATEY_SOURCE', - args: '-v pipcache_speedwagon:c:/users/containeradministrator/appdata/local/pip' + additionalBuildArgs: '--build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL --build-arg CHOCOLATEY_SOURCE' ] ], - glob: 'dist/*.whl', - stash: 'PYTHON_PACKAGES', - toxEnv: "py${pythonVersion.replace('.', '')}-PySide6", - retry: 3, + retries: 3, + testSetup: { + checkout scm + unstash 'PYTHON_PACKAGES' + }, + testCommand: { + findFiles(glob: 'dist/*.whl').each{ + powershell(label: 'Running Tox', script: "tox --installpkg ${it.path} --workdir \$env:TEMP\\tox -e py${pythonVersion.replace('.', '')}-PySide6") + } + + }, + post:[ + cleanup: { + cleanWs( + patterns: [ + [pattern: 'dist/', type: 'INCLUDE'], + [pattern: '**/__pycache__/', type: 'INCLUDE'], + ], + notFailBuild: true, + deleteDirs: true + ) + }, + ] ) } } @@ -415,7 +451,7 @@ def testPythonPackages(){ } architectures.each{ processorArchitecture -> linuxTests["Linux-${processorArchitecture} - Python ${pythonVersion}: sdist"] = { - packages.testPkg2( + packages.testPkg( agent: [ dockerfile: [ label: "linux && docker && ${processorArchitecture}", @@ -424,14 +460,35 @@ def testPythonPackages(){ args: '-v pipcache_speedwagon:/.cache/pip' ] ], - glob: 'dist/*.tar.gz', - stash: 'PYTHON_PACKAGES', - toxEnv: processorArchitecture=='arm' ? "py${pythonVersion.replace('.', '')}" : "py${pythonVersion.replace('.', '')}-PySide6", - retry: 3, + retries: 3, + testSetup: { + checkout scm + unstash 'PYTHON_PACKAGES' + }, + testCommand: { + findFiles(glob: 'dist/*.tar.gz').each{ + sh( + label: 'Running Tox', + script: "tox --installpkg ${it.path} --workdir /tmp/tox -e py${pythonVersion.replace('.', '')}-PySide6" + ) + } + }, + post:[ + cleanup: { + cleanWs( + patterns: [ + [pattern: 'dist/', type: 'INCLUDE'], + [pattern: '**/__pycache__/', type: 'INCLUDE'], + ], + notFailBuild: true, + deleteDirs: true + ) + }, + ] ) } linuxTests["Linux-${processorArchitecture} - Python ${pythonVersion}: wheel"] = { - packages.testPkg2( + packages.testPkg( agent: [ dockerfile: [ label: "linux && docker && ${processorArchitecture}", @@ -440,10 +497,31 @@ def testPythonPackages(){ args: '-v pipcache_speedwagon:/.cache/pip' ] ], - glob: 'dist/*.whl', - stash: 'PYTHON_PACKAGES', - toxEnv: processorArchitecture=='arm' ? "py${pythonVersion.replace('.', '')}" : "py${pythonVersion.replace('.', '')}-PySide6", - retry: 3, + retries: 3, + testSetup: { + checkout scm + unstash 'PYTHON_PACKAGES' + }, + testCommand: { + findFiles(glob: 'dist/*.whl').each{ + sh( + label: 'Running Tox', + script: "tox --installpkg ${it.path} --workdir /tmp/tox -e py${pythonVersion.replace('.', '')}-PySide6" + ) + } + }, + post:[ + cleanup: { + cleanWs( + patterns: [ + [pattern: 'dist/', type: 'INCLUDE'], + [pattern: '**/__pycache__/', type: 'INCLUDE'], + ], + notFailBuild: true, + deleteDirs: true + ) + }, + ] ) } } @@ -460,55 +538,75 @@ def testPythonPackages(){ } architectures.each{ processorArchitecture -> macTests["Mac - ${processorArchitecture} - Python ${pythonVersion}: wheel"] = { - packages.testPkg2( + packages.testPkg( agent: [ label: "mac && python${pythonVersion} && ${processorArchitecture}", ], - glob: 'dist/*.tar.gz,dist/*.zip', - stash: 'PYTHON_PACKAGES', - toxEnv: "py${pythonVersion.replace('.', '')}-PySide6", - toxExec: 'venv/bin/tox', + retries: 3, testSetup: { checkout scm unstash 'PYTHON_PACKAGES' - sh( - label:'Install Tox', - script: '''python3 -m venv venv - venv/bin/pip install pip --upgrade - venv/bin/pip install -r requirements/requirements_tox.txt - ''' - ) }, - testTeardown: { - sh 'rm -r venv/' + testCommand: { + findFiles(glob: 'dist/*.whl').each{ + sh(label: 'Running Tox', + script: """python${pythonVersion} -m venv venv + ./venv/bin/python -m pip install --upgrade pip + ./venv/bin/pip install -r requirements/requirements_tox.txt + ./venv/bin/tox --installpkg ${it.path} -e py${pythonVersion.replace('.', '')}-PySide6""" + ) + } + }, - retry: 3, + post:[ + cleanup: { + cleanWs( + patterns: [ + [pattern: 'dist/', type: 'INCLUDE'], + [pattern: 'venv/', type: 'INCLUDE'], + [pattern: '.tox/', type: 'INCLUDE'], + ], + notFailBuild: true, + deleteDirs: true + ) + }, + ] ) } macTests["Mac - ${processorArchitecture} - Python ${pythonVersion}: sdist"] = { - packages.testPkg2( + packages.testPkg( agent: [ label: "mac && python${pythonVersion} && ${processorArchitecture}", ], - glob: 'dist/*.tar.gz,dist/*.zip', - stash: 'PYTHON_PACKAGES', - toxEnv: "py${pythonVersion.replace('.', '')}-PySide6", - toxExec: 'venv/bin/tox', + retries: 3, testSetup: { checkout scm unstash 'PYTHON_PACKAGES' - sh( - label:'Install Tox', - script: '''python3 -m venv venv - venv/bin/pip install pip --upgrade - venv/bin/pip install -r requirements/requirements_tox.txt - ''' - ) }, - testTeardown: { - sh 'rm -r venv/' + testCommand: { + findFiles(glob: 'dist/*.tar.gz').each{ + sh(label: 'Running Tox', + script: """python${pythonVersion} -m venv venv + ./venv/bin/python -m pip install --upgrade pip + ./venv/bin/pip install -r requirements/requirements_tox.txt + ./venv/bin/tox --installpkg ${it.path} -e py${pythonVersion.replace('.', '')}-PySide6""" + ) + } + }, - retry: 3, + post:[ + cleanup: { + cleanWs( + patterns: [ + [pattern: 'dist/', type: 'INCLUDE'], + [pattern: 'venv/', type: 'INCLUDE'], + [pattern: '.tox/', type: 'INCLUDE'], + ], + notFailBuild: true, + deleteDirs: true + ) + }, + ] ) } } @@ -516,6 +614,18 @@ def testPythonPackages(){ parallel(linuxTests + windowsTests + macTests) } } +def buildPackages(){ + timeout(5){ + withEnv(['PIP_NO_CACHE_DIR=off']) { + sh(label: 'Building Python Package', + script: '''python -m venv venv --upgrade-deps + venv/bin/pip install build + venv/bin/python -m build . + ''' + ) + } + } +} def buildSphinx(){ def sphinx = load('ci/jenkins/scripts/sphinx.groovy') @@ -872,16 +982,7 @@ pipeline { } } steps{ - timeout(5){ - withEnv(['PIP_NO_CACHE_DIR=off']) { - sh(label: 'Building Python Package', - script: '''python -m venv venv --upgrade-deps - venv/bin/pip install build - venv/bin/python -m build . - ''' - ) - } - } + buildPackages() } post{ always{ @@ -1420,7 +1521,8 @@ pipeline { script{ if (!env.TAG_NAME?.trim()){ checkout scm - docker.build('speedwagon:devpi','-f ./ci/docker/python/linux/jenkins/Dockerfile --build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL .').inside{ + def dockerImage = docker.build('speedwagon:devpi','-f ./ci/docker/python/linux/jenkins/Dockerfile --build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL .') + dockerImage.inside{ load('ci/jenkins/scripts/devpi.groovy').pushPackageToIndex( pkgName: props.name, pkgVersion: props.version, @@ -1430,6 +1532,7 @@ pipeline { credentialsId: DEVPI_CONFIG.credentialsId, ) } + sh script: "docker image rm --no-prune ${dockerImage.imageName()}" } } } @@ -1438,7 +1541,8 @@ pipeline { node('linux && docker && x86 && devpi-access') { script{ checkout scm - docker.build('speedwagon:devpi','-f ./ci/docker/python/linux/jenkins/Dockerfile --build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL .').inside{ + def dockerImage = docker.build('speedwagon:devpi','-f ./ci/docker/python/linux/jenkins/Dockerfile --build-arg PIP_EXTRA_INDEX_URL --build-arg PIP_INDEX_URL .') + dockerImage.inside{ load('ci/jenkins/scripts/devpi.groovy').removePackage( pkgName: props.name, pkgVersion: props.version, @@ -1448,6 +1552,7 @@ pipeline { ) } + sh script: "docker image rm --no-prune ${dockerImage.imageName()}" } } } diff --git a/ci/jenkins/scripts/devpi.groovy b/ci/jenkins/scripts/devpi.groovy index 6afb394d8..afb01a4e5 100644 --- a/ci/jenkins/scripts/devpi.groovy +++ b/ci/jenkins/scripts/devpi.groovy @@ -3,52 +3,48 @@ def upload(args = [:]){ def clientDir = args['clientDir'] ? args['clientDir']: './devpi' def index = args['index'] def devpiExec = args['devpiExec'] ? args['devpiExec']: "devpi" - withCredentials([usernamePassword( - credentialsId: credentialsId, - passwordVariable: 'DEVPI_PASSWORD', - usernameVariable: 'DEVPI_USERNAME' - ) - ]) - { - withEnv([ - "DEVPI_SERVER=${args['server']}", - "CLIENT_DIR=${clientDir}", - "DEVPI=${devpiExec}" - ]) { - withEnv([ - "INDEX=${args['server']}/${DEVPI_USERNAME}/${index}", - ]) { - if(isUnix()){ - sh(label: 'Logging into DevPi', - script: '''$DEVPI use $DEVPI_SERVER --clientdir $CLIENT_DIR - $DEVPI login $DEVPI_USERNAME --password=$DEVPI_PASSWORD --clientdir $CLIENT_DIR - ''' - ) - } else { - bat(label: 'Logging into DevPi', - script: '''%DEVPI% use %DEVPI_SERVER% --clientdir %CLIENT_DIR% - %DEVPI% login %DEVPI_USERNAME% --password %DEVPI_PASSWORD% --clientdir %CLIENT_DIR% - ''' - ) - } - } - withEnv(["INDEX=/${DEVPI_USERNAME}/${index}"]){ - if(isUnix()){ - sh(label: 'Uploading to DevPi Staging', - script: '''$DEVPI use --clientdir $CLIENT_DIR --debug - $DEVPI upload --from-dir dist --clientdir $CLIENT_DIR --debug --index $INDEX - ''' - ) - } else { - bat(label: 'Uploading to DevPi Staging', - script: '''%DEVPI% use %INDEX% --clientdir %CLIENT_DIR% - %DEVPI% upload --from-dir dist --clientdir %CLIENT_DIR% - ''' - ) - } + + withEnv([ + "DEVPI_SERVER=${args['server']}", + "CLIENT_DIR=${clientDir}", + "DEVPI=${devpiExec}", + "INDEX=${index}" + ]) { + withCredentials( + [ + usernamePassword( + credentialsId: credentialsId, + passwordVariable: 'DEVPI_PASSWORD', + usernameVariable: 'DEVPI_USERNAME' + ) + ] + ) + { + if(isUnix()){ + sh(label: 'Logging into DevPi', + script: '''$DEVPI use $DEVPI_SERVER --clientdir $CLIENT_DIR + $DEVPI login $DEVPI_USERNAME --password=$DEVPI_PASSWORD --clientdir $CLIENT_DIR + ''' + ) + sh(label: 'Uploading to DevPi Staging', + script: '''$DEVPI use --clientdir $CLIENT_DIR --debug + $DEVPI upload --from-dir dist --clientdir $CLIENT_DIR --debug --index $DEVPI_USERNAME/$INDEX + ''' + ) + } else { + bat(label: 'Logging into DevPi', + script: '''%DEVPI% use %DEVPI_SERVER% --clientdir %CLIENT_DIR% + %DEVPI% login %DEVPI_USERNAME% --password %DEVPI_PASSWORD% --clientdir %CLIENT_DIR% + ''' + ) + bat(label: 'Uploading to DevPi Staging', + script: '''%DEVPI% use %INDEX% --clientdir %CLIENT_DIR% + %DEVPI% upload --from-dir dist --clientdir %CLIENT_DIR% --index %DEVPI_USERNAME%/%INDEX% + ''' + ) } } - } + } } def pushPackageToIndex(args = [:]){ @@ -144,7 +140,6 @@ def removePackage(args = [:]){ ${devpi} remove -y --index ${index} ${pkgName}==${pkgVersion} --clientdir ${clientDir} """ ) - } } @@ -155,6 +150,15 @@ def getNodeLabel(agent){ } return label } +def getAgentLabel(args){ + if (args.agent.containsKey("label")){ + return args.agent['label'] + } + if (args.agent.containsKey("dockerfile")){ + return args.agent.dockerfile.label + } + error('Invalid agent type, expect [dockerfile,label]') +} def getAgent(args){ if (args.agent.containsKey("label")){ @@ -168,17 +172,34 @@ def getAgent(args){ } if (args.agent.containsKey("dockerfile")){ + def runArgs = args.agent.dockerfile.containsKey('args') ? args.agent.dockerfile['args']: '' return { inner -> node(args.agent.dockerfile.label){ ws{ checkout scm def dockerImage - def dockerImageName = "${currentBuild.fullProjectName}_devpi".replaceAll("-", "_").replaceAll('/', "_").replaceAll(' ', "").toLowerCase() + def dockerImageName = "${currentBuild.fullProjectName}_devpi_${UUID.randomUUID().toString()}".replaceAll("-", "_").replaceAll('/', "_").replaceAll(' ', "").toLowerCase() lock("docker build-${env.NODE_NAME}"){ dockerImage = docker.build(dockerImageName, "-f ${args.agent.dockerfile.filename} ${args.agent.dockerfile.additionalBuildArgs} .") } - dockerImage.inside(){ - inner() + try{ + dockerImage.inside(runArgs){ + inner() + } + } finally { + if(isUnix()){ + sh( + label: "Untagging Docker Image used", + script: "docker image rm --no-prune ${dockerImage.imageName()}", + returnStatus: true + ) + } else { + powershell( + label: "Untagging Docker Image used", + script: "docker image rm --no-prune ${dockerImage.imageName()}", + returnStatus: true + ) + } } } } @@ -219,16 +240,26 @@ def logIntoDevpiServer(devpiExec, serverUrl, credentialsId, clientDir){ } def runDevpiTest(devpiExec, devpiIndex, pkgName, pkgVersion, pkgSelector, clientDir, toxEnv){ - if(isUnix()){ - sh( - label: "Running tests on Packages on DevPi", - script: "${devpiExec} test --index ${devpiIndex} ${pkgName}==${pkgVersion} -s ${pkgSelector} --clientdir ${clientDir} -e ${toxEnv} -v" - ) - } else{ - bat( - label: "Running tests on Packages on DevPi", - script: "${devpiExec} test --index ${devpiIndex} ${pkgName}==${pkgVersion} -s ${pkgSelector} --clientdir ${clientDir} -e ${toxEnv} -v" - ) + withEnv([ + "DEVPI=${devpiExec}", + "_DEVPI_INDEX=${devpiIndex}", + "CLIENT_DIR=${clientDir}", + "PACKAGE_NAME=${pkgName}", + "PACKAGE_VERSION=${pkgVersion}", + "TOX_ENV=${toxEnv}", + "TOX_PACKAGE_SELECTOR=${pkgSelector}", + ]){ + if(isUnix()){ + sh( + label: 'Running tests on Packages on DevPi', + script: '$DEVPI test --index $_DEVPI_INDEX $PACKAGE_NAME==$PACKAGE_VERSION -s $TOX_PACKAGE_SELECTOR --clientdir $CLIENT_DIR -e $TOX_ENV -v' + ) + } else{ + bat( + label: 'Running tests on Packages on DevPi', + script: '%DEVPI% test --index %_DEVPI_INDEX% %PACKAGE_NAME%==%PACKAGE_VERSION% -s %TOX_PACKAGE_SELECTOR% --clientdir %CLIENT_DIR% -e %TOX_ENV% -v' + ) + } } } @@ -254,14 +285,24 @@ def testDevpiPackage2(args=[:]){ def toxEnv = args.test.toxEnv def testSetup = args.test['setup'] ? args.test['setup'] : {} def testTeardown = args.test['teardown'] ? args.test['teardown'] : {} - - agent{ - testSetup() - try{ - logIntoDevpiServer(devpiExec, devpiServerUrl, credentialsId, clientDir) - runDevpiTest(devpiExec, devpiIndex, pkgName, pkgVersion, pkgSelector, clientDir, toxEnv) - } finally { - testTeardown() + def retries = args['retries'] ? args['retries'] : 1 + def attempt = 1 + retry(retries){ + agent{ + testSetup() + try{ + logIntoDevpiServer(devpiExec, devpiServerUrl, credentialsId, clientDir) + runDevpiTest(devpiExec, devpiIndex, pkgName, pkgVersion, pkgSelector, clientDir, toxEnv) + } catch(Exception e){ + if (attempt < retries) { + echo 'Waiting 5 seconds' + sleep 5; + } + throw e; + }finally { + testTeardown() + attempt += 1 + } } } } @@ -270,4 +311,4 @@ return [ removePackage: this.&removePackage, pushPackageToIndex: this.&pushPackageToIndex, upload: this.&upload -] \ No newline at end of file +] diff --git a/ci/jenkins/scripts/packaging.groovy b/ci/jenkins/scripts/packaging.groovy index cb569b07a..67e01be85 100644 --- a/ci/jenkins/scripts/packaging.groovy +++ b/ci/jenkins/scripts/packaging.groovy @@ -13,6 +13,15 @@ def getToxEnv(args){ return "py" } } +def getDockerRuntimeArgs(agent){ + def args + if (agent.containsKey("dockerfile")){ + if (agent.dockerfile.containsKey("args")){ + return agent.dockerfile.args + } + } + return "" +} def getAgent(args){ if (args.agent.containsKey("label")){ @@ -28,18 +37,34 @@ def getAgent(args){ if (args.agent.containsKey("dockerfile")){ def nodeLabel = getNodeLabel(args.agent) + def dockerArgs = getDockerRuntimeArgs(args.agent) return { inner -> node(nodeLabel){ ws{ checkout scm def dockerImage - def dockerImageName = "${currentBuild.fullProjectName}_${getToxEnv(args)}".replaceAll("-", "_").replaceAll('/', "_").replaceAll(' ', "").toLowerCase() + def dockerImageName = "${currentBuild.fullProjectName}_${getToxEnv(args)}_${UUID.randomUUID().toString()}".replaceAll("-", "_").replaceAll('/', "_").replaceAll(' ', "").toLowerCase() lock("docker build-${env.NODE_NAME}"){ dockerImage = docker.build(dockerImageName, "-f ${args.agent.dockerfile.filename} ${args.agent.dockerfile.additionalBuildArgs} .") } - def dockerRunArgs = args.agent.dockerfile.get('args', '') - dockerImage.inside(dockerRunArgs){ - inner() + try{ + dockerImage.inside(dockerArgs){ + inner() + } + } finally{ + if(isUnix()){ + sh( + label: "Untagging Docker Image used", + script: "docker image rm --no-prune ${dockerImage.imageName()}", + returnStatus: true + ) + } else { + powershell( + label: "Untagging Docker Image used", + script: "docker image rm --no-prune ${dockerImage.imageName()}", + returnStatus: true + ) + } } } } @@ -49,70 +74,76 @@ def getAgent(args){ } def testPkg(args = [:]){ - def tox = args['toxExec'] ? args['toxExec']: "tox" + def testCommand = args['testCommand'] ? args['testCommand']: { + def distroFiles = findFiles(glob: 'dist/*.tar.gz,dist/*.zip,dist/*.whl') + if (distroFiles.size() == 0){ + error("No files located to test") + } + distroFiles.each{ + def toxCommand = "tox --installpkg ${it.path} -e py" + if(isUnix()){ + sh(label: "Testing tox version", script: "tox --version") + toxCommand = toxCommand + " --workdir /tmp/tox" + sh(label: "Running Tox", script: toxCommand) + } else{ + bat(label: "Testing tox version", script: "tox --version") + toxCommand = toxCommand + " --workdir %TEMP%\\tox" + bat(label: "Running Tox", script: toxCommand) + } + } + } def setup = args['testSetup'] ? args['testSetup']: { checkout scm - unstash "${args.stash}" } - def teardown = args['testTeardown'] ? args['testTeardown']: {} - def retries = args.containsKey('retry') ? args.retry : 1 + def cleanup = args['post']['cleanup'] ? args['post']['cleanup']: {} + def successful = args['post']['success'] ? args['post']['success']: {} + def failure = args['post']['failure'] ? args['post']['failure']: {} + def dockerImageName = args['dockerImageName'] ? args['dockerImageName']: "${currentBuild.fullProjectName}_${getToxEnv(args)}_build".replaceAll("-", "_").replaceAll('/', "_").replaceAll(' ', "").toLowerCase() def agentRunner = getAgent(args) - retry(retries){ - agentRunner { - setup() - try{ - findFiles(glob: args.glob).each{ - def toxCommand = "${tox} --installpkg ${it.path} -e ${getToxEnv(args)} -vv" - if(isUnix()){ - sh(label: "Testing tox version", script: "${tox} --version") - sh(label: "Running Tox", script: toxCommand) - } else{ - bat(label: "Testing tox version", script: "${tox} --version") - toxCommand = toxCommand + " --workdir %TEMP%\\tox" - bat(label: "Running Tox", script: toxCommand) - } - } - } finally{ - teardown() - } + agentRunner { + setup() + try{ + testCommand() + successful() + } catch(e){ + failure() + throw e + } finally{ + cleanup() } } } - -def testPkg2(args = [:]){ - def tox = args['toxExec'] ? args['toxExec']: "tox" - def setup = args['testSetup'] ? args['testSetup']: { +def buildPkg(args = [:]){ + def agentRunner = getAgent(args) + def setup = args['buildSetup'] ? args['buildSetup']: { checkout scm - unstash "${args.stash}" } - def toxEnv = args['toxEnv'] ? args['toxEnv']: "py" - def teardown = args['testTeardown'] ? args['testTeardown']: {} - def retries = args.containsKey('retry') ? args.retry : 1 - def agentRunner = getAgent(args) - retry(retries){ - agentRunner { - setup() - try{ - findFiles(glob: args.glob).each{ - def toxCommand = "${tox} --installpkg ${it.path} -e ${toxEnv} -vv" - if(isUnix()){ - sh(label: "Testing tox version", script: "${tox} --version") - sh(label: "Running Tox", script: toxCommand) - } else{ - bat(label: "Testing tox version", script: "${tox} --version") - toxCommand = toxCommand + " --workdir %TEMP%\\tox" - bat(label: "Running Tox", script: toxCommand) - } - } - } finally{ - teardown() - } + def cleanup = args['post']['cleanup'] ? args['post']['cleanup']: {} + def successful = args['post']['success'] ? args['post']['success']: {} + def failure = args['post']['failure'] ? args['post']['failure']: {} + def buildCmd = args['buildCmd'] ? args['buildCmd']: { + if(isUnix()){ + sh "python -m pip wheel --no-deps -w ./dist ." + } else { + bat "py -m pip wheel --no-deps -w ./dist ." + } + } + def retries = args['retries'] ? args['retries'] : 1 + agentRunner { + setup() + try{ + buildCmd() + successful() + } catch(e){ + failure() + throw e + } finally{ + cleanup() } } } - return [ testPkg: this.&testPkg, - testPkg2: this.&testPkg2 + buildPkg: this.&buildPkg ] \ No newline at end of file