Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Jenkins pipeline python virtualenv workarounds
node {
stage 'Checkout and Build'
createVirtualEnv 'env'
executeIn 'env', 'pip install -r requirements.txt'
executeIn 'env', './ test'
executeIn 'env', './ integration-test'
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){
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){
sh returnStatus: true, script: "vex --path=${env.VENV_PATH} ${pyCmd}"

This comment has been minimized.

Copy link

@verystrongjoe verystrongjoe commented Dec 4, 2017

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