somexp12
somexp12

Reputation: 547

NPM works on Command Line, but not in Jenkins

I am having trouble getting Jenkins to use the "npm" command from the "Execute shell" (under the "Build" step).

I am attempting to set up a new Jenkins instance (a copy from a previous one). I just imported the old jobs and am now getting the various services that these jobs depend on (e.g. maven, nodejs, ansible etc.) installed.

I am having trouble getting nodejs and npm, in particular, set up.

When I type the command "npm install" on the command line, I get the following:

[email protected] install /var/lib/jenkins/workspace . . .
. . . 
Binary is fine
added 1282 packages in 36.424s

When I then attempt to run the same command using the Jenkins execute shell, I get the following:

+ npm install
/tmp/jenkins7750702649955218109.sh: line 2: npm: command not found
Build step 'Execute shell' marked build as failure

Why would this command be accessible to me from the command line but not to Jenkins?

Some things I have checked:

-The path to "node" and "npm" are both on the path. At least "shortcuts" are on the path (this worked in the previous Jenkins instance).

-The node and npm binaries have root:root ownership, but their security settings are (currently) 755 (or -rwxr-xr-x).

-I have the nodejs plugin installed. Not sure of how to use it, but its settings match those on the previous Jenkins instance. Both instances use the execute shell (as opposed to any special Jenkins tool) to run the "npm" commands, whilst only the old version worked.

So, what else should I be checking that I am not? What does Jenkins require to access the "npm" command?

Upvotes: 3

Views: 7995

Answers (1)

Balakrishnan
Balakrishnan

Reputation: 299

Try this below options in Jenkins

Option 1:

enter image description here

Option 2:

enter image description here

Upvotes: 4

Related Questions