Created
April 13, 2017 08:14
-
-
Save jubel-han/0e669dbbfa9e966f0b79a91730edc806 to your computer and use it in GitHub Desktop.
Jenkins pipeline python virtualenv workarounds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node { | |
stage 'Checkout and Build' | |
createVirtualEnv 'env' | |
executeIn 'env', 'pip install -r requirements.txt' | |
executeIn 'env', './manage.py test' | |
executeIn 'env', './manage.py integration-test' | |
virtualEnv('true') | |
runCmd('pip install -r requirements.txt') | |
} | |
// one of the workaround | |
def createVirtualEnv(String name) { | |
sh "virtualenv ${name}" | |
} | |
def executeIn(String environment, String script) { | |
sh "source ${environment}/bin/activate && " + script | |
} | |
// alternative workaround | |
env.VENV_PATH = "${JENKINS_HOME}/.virtualenv/${JOB_NAME}/venv" | |
def virtualEnv(String rebuild){ | |
withEnv(["PATH+VEX=~/.local/bin"]){ | |
if(rebuild == "true") { | |
sh "rm -rf ${env.VENV_PATH}" | |
sh "echo 'rebuild is true'" | |
} | |
sh returnStatus: true, script: "virtualenv ${env.VENV_PATH}" | |
} | |
} | |
def runCmd(String pyCmd){ | |
withEnv(["PATH+VEX=~/.local/bin"]){ | |
sh returnStatus: true, script: "vex --path=${env.VENV_PATH} ${pyCmd}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script can be working on Windows?