Edin Puzic
Edin Puzic

Reputation: 1048

Jenkins: -bash: command not found

I'm trying to build my Node.js application using Jenkins, but I'm getting this error:

    -bash: npm: command not found
    -bash: pm2: command not found
    Build step 'Execute shell' marked build as failure
    Finished: FAILURE

I created a deploy file and added it to my Execute shell in Jenkins, and it looks like this:

-#!/bin/sh
ssh ubuntu@development-server:ip <<EOF
    cd ~/nodeweb
    git pull
    npm install
    pm2 restart ecosystem.config.js
    exit
EOF

On my development server, I have installed the npm and pm2 modules.

Upvotes: 1

Views: 2519

Answers (1)

Royden Rego
Royden Rego

Reputation: 132

This is because a normal ssh session opens the shell in non-interactive mode and does not source the .bashrc file.

The PATH for your npm and pm2 modules could be configured in the .bashrc file and thereby throws the not found error when you try to do npm install via the non-interactive shell.

For ssh to use the interactive mode simply use -i flag in your ssh command.

#!/bin/sh
ssh ubuntu@development-server:ip 'bash -i' <<EOF
    cd ~/nodeweb
    git pull
    npm install
    pm2 restart ecosystem.config.js
    exit
EOF

Upvotes: 1

Related Questions