Jenkins pipeline : select nodejs version (+ python version)
So. This is a problem from "EnvInject" plugin: https://issues.jenkins-ci.org/browse/JENKINS-26583
My workaround #4 above is the correct solution if you want to keep EnvInject.
env.NODE_HOME="${tool 'Node 6.x'}"
env.PATH="${env.NODE_HOME}/bin:${env.PATH}"
sh 'npm -version'
Otherwise, removing EnvInject plugin is also a good solution when possible.
pipeline {
agent {
label 'slave-machine'
}
environment {
NODE_HOME = tool name: 'Node 10.13.0', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
}
stages {
stage('test') {]
steps {
script {
env.PATH="${env.NODE_HOME}/bin:${env.PATH}"
sh 'node -v'
sh 'echo $NODE_HOME'
}
}
}
}
}