changeset 6550:ad275fcc5a90

jenkinsfile: create venv in special folder instead of jenkins workspace The path to a jenkins workspace tends to get very long. But the maximum for a shebang line is usually 127 characters. This can cause problems with git hook scripts or when calling pip. To avoid these problems create the virtualenv in the a folder under $JENKINS_HOME which is usually much shorter.
author domruf <dominikruf@gmail.com>
date Thu, 23 Mar 2017 22:20:35 +0100
parents f65f8acaca84
children bc1b11a5d548
files Jenkinsfile
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Jenkinsfile	Thu Mar 23 22:08:56 2017 +0100
+++ b/Jenkinsfile	Thu Mar 23 22:20:35 2017 +0100
@@ -1,9 +1,12 @@
 node {
+    def createvirtualenv = ''
     def activatevirtualenv = ''
     if (isUnix()) {
-        activatevirtualenv = '. venv/bin/activate'
+        createvirtualenv = 'rm -r $JENKINS_HOME/venv/$JOB_NAME || true && virtualenv $JENKINS_HOME/venv/$JOB_NAME'
+        activatevirtualenv = '. $JENKINS_HOME/venv/$JOB_NAME/bin/activate'
     } else {
-        activatevirtualenv = 'call venv\\Scripts\\activate.bat'
+        createvirtualenv = 'rmdir /s /q %JENKINS_HOME%\\venv\\%JOB_NAME% || true && virtualenv %JENKINS_HOME%\\venv\\%JOB_NAME%'
+        activatevirtualenv = 'call %JENKINS_HOME%\\venv\\%JOB_NAME%\\Scripts\\activate.bat'
     }
 
     stage('checkout') {
@@ -15,7 +18,7 @@
         }
     }
     stage('virtual env') {
-        def virtualenvscript = """virtualenv venv
+        def virtualenvscript = """$createvirtualenv
             $activatevirtualenv
             python -m pip install --upgrade pip
             pip install --upgrade setuptools