-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor
-
Component/s: nvm-wrapper-plugin
-
None
-
Environment:Jenkins ver. 2.164.2
nvm-wrapper-plugin 0.1.7
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() } } }