Search code examples
ubuntujenkinssshjenkins-pluginsnvm

when executing SSH command from jenkins nvm not found


I am working on an express app and trying to deploy it on ec2 with Jenkins. I used the terminal to install nvm and it's working fine.

In Jenkins, I used Publish Over SSH Plugin to upload the build to ec2 with the same user but it fails on npm install command.

I checked .bashrc and verified the nvm installation.

When I run printenv command from the shell it shows nvm in PATH

PATH=/home/ubuntu/.nvm/versions/node/v12.13.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

But when I run it from Jenkins job it is not there

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games _=/usr/bin/


Solution

  • Jenkins node / agent / slave launches a non-interactive shell, which skips the user .bashrc, only the system ( in /etc) profile. There are various workarounds beyond editing the system defaults.

    We use a combination of SSH Slaves Setup plugin and EnvInject.

    YMMV.