[JIRA] (JENKINS-57716) Path set by withEnv overwritten

23 views
Skip to first unread message

fredrik.broman@netent.com (JIRA)

unread,
May 28, 2019, 9:51:03 AM5/28/19
to jenkinsc...@googlegroups.com
Fredrik Broman created an issue
 
Jenkins / Bug JENKINS-57716
Path set by withEnv overwritten
Issue Type: Bug Bug
Assignee: Tomas Salazar
Components: nvm-wrapper-plugin
Created: 2019-05-28 13:50
Priority: Minor Minor
Reporter: Fredrik Broman

Hi,
Maybe this is intended behaviour (or maybe I'm doing something wrong) but if i have this test pipeline:

pipeline {    
    agent none    
    stages {       
      stage("nvm") {           
      agent {label 'npm'}           
          steps {            
             withEnv(["PATH+foo=/tmp"]) {            
                nvm('8.10.0') {                       
                   sh 'env'                   
               }               
           }          
       }      
    }  
  }
}

/tmp is not on PATH:
PATH=/var/opt/jenkins-slave/.nvm/versions/node/v8.10.0/bin:/var/opt/jenkins-slave/.nvm/versions/node/v8.10.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/rh/git19/root/bin

However if I just switch wtihEnv and nvm around:

 steps {  
       nvm('8.10.0') {   
           withEnv(["PATH+foo=/tmp"]) {           
               sh 'env'      
          }  
       }
}

/tmp is now on the PATH: 
PATH=/tmp:/var/opt/jenkins-slave/.nvm/versions/node/v8.10.0/bin:/var/opt/jenkins-slave/.nvm/versions/node/v8.10.0/bin:/goss:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/rh/git19/root/bin

 Why does this matter to me? Because our Shared Library currently has...

 withJava() {  
withMaven() {  
withNode() {  
//build node with maven (don't ask) but mvn not on PATH in this case
  } 
 } 
}

 ... all over the place and while refactoring it by moving the order of theses statements around isn't a biggie it's not very nice to have code that only works if the statements are in a certain order.

 So tl;dr: please change the behaviour of the code not to overwrite PATH set by withEnv or advise on some other way to work around this.
 
Content of withNode:

def call(String nodeVersion, Closure body) {

    nvm(nodeVersion) {
        configFileProvider([configFile(fileId: Constants.NODEJS_SETTINGS_ID, targetLocation: '/var/opt/jenkins-slave/.npmrc')]) {
            body()
        }
    }
}

withMaven() uses withEnv internally:

def call(String mavenVersion, Closure body) {

    def maven_home = tool name: "Maven ${mavenVersion}", type: 'maven'
    buildlog.info("MAVEN_HOME: ${maven_home}")

    withEnv(["PATH+MAVEN=${maven_home}/bin", "MAVEN_VERSION=${mavenVersion}"]) {
        configFileProvider([configFile(fileId: Constants.MAVEN_SETTINGS_ID, targetLocation: 'settings.xml', variable: 'MAVEN_SETTINGS')]) {
            body()
        }

    }
}
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

fredrik.broman@netent.com (JIRA)

unread,
May 29, 2019, 3:13:02 AM5/29/19
to jenkinsc...@googlegroups.com
Fredrik Broman updated an issue
Change By: Fredrik Broman
Environment: Jenkins ver. 2.164.2
nvm-wrapper-plugin 0.1.7

atomsmail+ci@gmail.com (JIRA)

unread,
Dec 26, 2019, 11:51:03 AM12/26/19
to jenkinsc...@googlegroups.com
Tomas Salazar started work on Bug JENKINS-57716
 
Change By: Tomas Salazar
Status: Open In Progress
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages