Skip to content

Instantly share code, notes, and snippets.

@jubel-han
Created April 13, 2017 08:14
Show Gist options
  • Save jubel-han/0e669dbbfa9e966f0b79a91730edc806 to your computer and use it in GitHub Desktop.
Save jubel-han/0e669dbbfa9e966f0b79a91730edc806 to your computer and use it in GitHub Desktop.
Jenkins pipeline python virtualenv workarounds
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}"
}
}
@verystrongjoe
Copy link

This script can be working on Windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment