Jenkins unable to find npm Jenkins unable to find npm linux linux

Jenkins unable to find npm


I have been battling with this for some time now. Finally found the solution. From your jobs menu select Configure under Build Environment select Provide Node & npm bin/ folder to PATH You can leave the default setting and you are good to go.

enter image description here

As specified by Eric Wang in the comments, the NodeJS Plugin needs to be installed first for this option to come up:https://wiki.jenkins.io/display/JENKINS/NodeJS+Plugin


The answers in this thread didn't help me, what helped was adding the node.js tool to my Jenkinsfile:

pipeline {  agent any  tools {nodejs "nodejs"}  stages {    stage('Example') {      steps {        sh 'npm config ls'      }    }  }}

Where the string "nodejs" is the name you give the node.js tool in the global tool configuration


Just install the nodeJS plugin for jenkins, you can find it here.

After installing the plugin, restart jenkins, and go to the global configs to specify the version.

The full details of configurations can be found in the plugin documentation linked above.


Update for jenkins 2.x

To get to the plugin page in jenkins 2.x:

simply go to Manage Jenkins > Manage Plugins view, available to administrators of a Jenkins environment. - https://jenkins.io/doc/book/managing/plugins/

However, I do recommend using pipelines instead of a plugin for the CI process:

Pipelines are instructions to describe portions of your software delivery pipeline.

Add this pipeline config to your node.js project on jenkins to have it running.

pipeline {    agent {        docker {            image 'node:6-alpine'            args '-p 3000:3000'        }    }    environment {        CI = 'true'     }    stages {        stage('Build') {            steps {                sh 'npm install'            }        }        stage('Test') {             steps {                sh './jenkins/scripts/test.sh'             }        }    }}

As you can see this runs two stages, building and testing for the application. npm is installed through the docker image node:6-alpine.

Jenkins docs provide a full tutorial to build a nodejs app through CI: https://jenkins.io/doc/tutorials/build-a-node-js-and-react-app-with-npm/