0
votes

This is my first Jenkins pipeline project. I created a simple Node.js application, and I uploaded into hithub (public repo) and all I am trying to do with my Jenkinsfile is to "npm install" in my Build stage. I believe Jenkins is finding the Jenkinsfile but it is just not finding the npm. I am using jenkins official docker image to run my jenkins server. Here are the two plugging that I have installed

1) NodeJS Plugin and 2) Pipeline NPM Integration Plugin

and here is the file

 pipeline {                                                                                                       
     agent any
     stages {
        stage ("Build") {
           steps {
              sh "npm install"
           }
        }
     }
  }

and this is the error I am getting when I run my 'Build Now' [second project] Running shell script + npm install

/var/jenkins_home/workspace/second project@tmp/durable-ef33ffd4/script.sh: 2: /var/jenkins_home/workspace/second project@tmp/durable-ef33ffd4/script.sh:

npm: not found

can someone help?

3

3 Answers

1
votes

I suppose, your npm binary isn't in PATH variable. Try to specify full path to npm, usually it's /usr/bin

 pipeline {                                                                                                       
     agent any
     stages {
        stage ("Build") {
           steps {
              sh "/usr/bin/npm install"
           }
        }
     }
  }

You can check npm path in console using command which npm

0
votes

May be, you already figured this. Have you hosted your machine's docket socket in the container when you started the Jenkins container?

Specifically, you need use -v /var/run/docker.sock:/var/run/docker.sock on your docker run command.

Then in your pipeline, you need to run the npm on a docker container that is built it from official node docker image, such as node:10.11.0-alpine. Here is an example

pipeline {                                                                                                       
     agent {
        docker {
          image 'node:10.11.0-alpine'
        }
     }
     stages {
        stage ("Build") {
           steps {
              sh "npm install"
           }
        }
     }
  }
-1
votes

If you are on windows than try to run CMD as Administrator and then install NPM it will work for you