How to use jenkins pipeline with nvm wrapper plugin?

Viewed 6797

I'm using pipeline (Jenkinsfile) and I need to change node version. i added the Nvm Wrapper Plugin but i don't know how to use it properly from Jenkinsfile

should i add the nvm('...') {} inside steps? or should it be somewhere top level in the node step? currently i don't even have the node step - everything is done using sh

3 Answers

this works for me

sh 'bash -l -c ". $HOME/.nvm/nvm.sh ; nvm use <version> || nvm install <version> && nvm use <version> "' 

example:

sh 'bash -l -c ". $HOME/.nvm/nvm.sh ; nvm use 8.0 || nvm install 8.0 && nvm use 8.0 "' 

I ended up using this and it works also with a .nvmrc file

sh 'bash -l -c ". $HOME/.nvm/nvm.sh ; nvm use || nvm install && nvm use"' 

This expects nvm installed in the jenkins home folder. But it would be easy to add a step that downloads nvm in the right place first.

Related