Reputation: 1438
Is there a way we can set NodeJS version dynamically in Jenkins Pipeline. I am not able to make available nvm as well inside the pipeline.
sh 'export NVM_DIR=~/.nvm'
sh 'source ~/.nvm/nvm.sh
script.sh: line 2: nvm: command not found
None of this helped. Multiple teams using the pipeline need specific version of nodeJS. Earlier with non-pipeline jobs, this used to work using nvm.
Upvotes: 1
Views: 4684
Reputation: 6334
You can create a choice
parameter and use it in tools declaration.
pipeline {
agent any
parameters {
choice(name: 'NODE_VERSION', choices: ['NodeJS 9.6.1', 'NodeJS 7.7.0'], description: '')
}
tools {
nodejs params.NODE_VERSION
}
stages{
stage("Run"){
steps{
sh 'node --version'
}
}
}
}
Upvotes: 4