Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NVM is not working on Jenkins execute shell

I am trying to install and use nvm from the Jenkins execute shell script on Ubuntu server but I am getting this error:

16:00:21 /tmp/hudson5983664925305072739.sh: line 8: nvm: command not found

This is what I have tried those so far but no success:

#!/bin/bash

touch ~/.profile && source ~/.profile;
nvm current || echo "SSH NVM is being installed" &&  touch ~/.profile && curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh && bash install_nvm.sh && source ~/.profile

echo "checking nvm"
bash ~/.nvm/nvm.sh;
nvm --version || exit 1;

Jenkins execute shell screenshot:

enter image description here

like image 936
mirza Avatar asked Mar 06 '17 13:03

mirza


3 Answers

Adding those solves the issue:

. ~/.nvm/nvm.sh
. ~/.profile
. ~/.bashrc
like image 180
mirza Avatar answered Nov 05 '22 05:11

mirza


You need to remember that Jenkins is running commands in non-interactive shell so PATH is different from what a normal user has. One way to solve this problem is to invoke nvm with it absolute path.

like image 33
Cosaquee Avatar answered Nov 05 '22 04:11

Cosaquee


After struggling to get the suggestions above to work, I tried the NodeJS Jenkins plugin and it worked like a charm.

https://plugins.jenkins.io/nodejs/

like image 6
Matthew S Avatar answered Nov 05 '22 05:11

Matthew S