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:
Adding those solves the issue:
. ~/.nvm/nvm.sh
. ~/.profile
. ~/.bashrc
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With