#!/usr/bin/groovy // vi: ft=groovy import hudson.model.* import hudson.EnvVars import groovy.json.JsonSlurperClassic import groovy.json.JsonBuilder import groovy.json.JsonOutput import java.net.URL try { node { properties([ parameters([ stringParam( defaultValue: 'git@192.168.2.168:GCloud/sv_ims.git', description: 'sv_ims repository url', name: 'repository_url' ), stringParam( defaultValue: 'http://192.168.2.168:8081/repository/sv-pypi-proxy/simple', description: 'Nexus 3 PYPI proxy url', name: 'NEXUS3_PYPI_PROXY_URL' ), stringParam( defaultValue: '192.168.2.168', description: 'Nexus 3 PYPI proxy server', name: 'NEXUS3_PYPI_PROXY_SERVER' ) ]) ]) stage("Fetching code") { git credentialsId: '56e2247e-2921-4df5-ab2f-336abcbf42b9', url: params.repository_url sh('cd $WORKSPACE && git rev-list --count HEAD > VERSION') def project_version = readFile('VERSION') sh('cd $WORKSPACE && git rev-parse HEAD > COMMIT') def commit = readFile('COMMIT') def short_commit = commit.take(8) } stage("Running Unit Test") { def workspace = pwd() echo "\u2600 workspace=${workspace}" sh """#!/bin/bash cd $WORKSPACE [ -d venv ] && rm -rf venv virtualenv venv venv/bin/pip install --upgrade pip setuptools venv/bin/pip install -r requirements.txt --index-url ${params.NEXUS3_PYPI_PROXY_URL} --trusted-host ${params.NEXUS3_PYPI_PROXY_SERVER} [ ! -d logs ] && mkdir logs cat << EOF >> src/sv_ims/settings/local.env DEBUG=True DATABASE_URL=sqlite:///db.sqlite3 SECRET_KEY=this_is_for_jenkins_test_and_package SV_AS_PRIVATE_KEY=this_is_for_testing SELF_HOST=http://localhost EOF source venv/bin/activate cd src pytest --junitxml results.xml """ junit allowEmptyResults: true, testResults: 'src/results.xml' } stage("Archiving artifact") { sh '''#!/bin/bash cd $WORKSPACE mkdir dist zip -r dist/sv_ims.zip . -x \'.*\' -x \'*/.*\' -x \'dist/*\' -x \'logs/*\' -x \'venv/*\' ''' archiveArtifacts 'dist/sv_ims.zip' } } } catch(caughtError) { err = caughtError currentBuild.result = "FAILURE" } finally { (currentBuild.result != "ABORTED") && node("master") { step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'ellery@solidyear.com.tw', sendToIndividuals: true]) } }