Error while running "npm install" command

468 views
Skip to first unread message

Sushma Gangaiah

unread,
Jun 3, 2021, 6:58:43 AM6/3/21
to go...@googlegroups.com
Hi All,

Hope everyone are doing well.
I am using GoCD version 19.9.0, since morning our builds are failing with below error

[go] Task: npm installtook: 0.46s
Error happened while attempting to execute 'npm install'.
Please make sure [npm] can be executed on this agent.
[Debug Information] Environment variable PATH: /usr/bin:/bin:/usr/sbin:/sbin
[go] Task status: failed, took: 0.46s
[go] Current job status: failed
 whereas this task was running completely fine till today morning

this below screenshot shows success of "npm install " command. Please advice

[go] Task: npm installtook: 25.161s
[go] Task: npm installtook: 33.196s
[go] Task: npm installtook: 1m 38.1

Please do not say to enclose this in shell script as this task was working till today morning

task block
            - exec:
                arguments:                
                - install
                commandnpm
                working_directory./abcd
                run_ifpassed
Regards,
Sushma

Marques Lee

unread,
Jun 3, 2021, 7:17:54 AM6/3/21
to go...@googlegroups.com
I would make sure you can hop on the agent and verify that it works if you exec npm manually as the same user running the agent service.

Perhaps your infrastructure changed if nothing else has? Check that the binary is still in the PATH, etc.

--
You received this message because you are subscribed to the Google Groups "go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/go-cd/CAHDZtpROhk9LpbZrzAPyKpeKmmZ9-rhwe7ptQFMdZv3ti69REw%40mail.gmail.com.

Sushma Gangaiah

unread,
Jun 3, 2021, 7:24:59 AM6/3/21
to go...@googlegroups.com, Marques Lee
Dear Marques,

1.Yes, I am able to run npm install command manually in go-agent.

2.There is no change in infrastructure
3.Binary path is in place.

Which is making me wonder . Please advise.

Regards,
Sushma



Sushma Gangaiah

unread,
Jun 3, 2021, 7:49:56 AM6/3/21
to Marques Lee, go...@googlegroups.com
Hi Marques,

Yes, I was executing as same agent user. Also this has been running since almost a year, but facing issue all of a sudden even though if there is no change in infrastructure . Which is making us wonder .Please help
npm path is in place. PFB screenshot.

pru7@pru7s-Mac-mini one-pulse-app % npm --version

6.14.4

pru7@pru7s-Mac-mini one-pulse-app % java --version

openjdk 11.0.7 2020-04-14

OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10)

OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)

pru7@pru7s-Mac-mini one-pulse-app % which npm

/usr/local/bin/npm

pru7@pru7s-Mac-mini one-pulse-app % cd

pru7@pru7s-Mac-mini ~ % command -v npm

/usr/local/bin/npm

pru7@pru7s-Mac-mini ~ % ls -l $(command -v npm)

lrwxr-xr-x  1 root  wheel  38 Jun 19  2020 /usr/local/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js

pru7@pru7s-Mac-mini ~ % 


Regards,

Sushma



On Thu, Jun 3, 2021 at 5:01 PM Marques Lee <marqu...@thoughtworks.com> wrote:
Were you execing npm as the same agent user?

Probably be good to find the path the npm and show its permissions bits

try:

1) command -v npm
2) then: ls -l $(command -v npm)

That should tell us the location of the binary and the flags. Just need to do a sanity check since I’m not certain where else to start until we verify these. The screenshot reported the value of the PATH variable, so just making sure npm is under that. When you execute manually, your PATH may be different from when invoked by gocd.

Marques Lee

unread,
Jun 3, 2021, 7:54:09 AM6/3/21
to Sushma Gangaiah, go...@googlegroups.com
Ok I see your problem now :).

Either the path to npm has changed or the PATH for the GoCD agent has changed.

npm is located in /use/local/bin

But according to the screenshot, /use/local/bin is not part of the PATH.

Only /usr/bin:/bin:/usr/sbin:/sbin

So, you’ll need to fix that. Then it should work.

-Marques

Sushma Gangaiah

unread,
Jun 3, 2021, 8:11:42 AM6/3/21
to Marques Lee, go...@googlegroups.com
Dear Marques,

Please advise me on how to change the invoke path for npm in GoCD. Because we have around 8 go-agents and all agents are building pipelines excluding one agent and npm path remains the same in all agents. 

Regards,
Sushma

Marques Lee

unread,
Jun 3, 2021, 8:15:29 AM6/3/21
to Sushma Gangaiah, go...@googlegroups.com
The easiest thing to do would be to specify the full path to npm instead of just “npm”

In other words, change your task to execute:
/usr/local/bin/npm install

Marques Lee

unread,
Jun 3, 2021, 8:20:14 AM6/3/21
to Sushma Gangaiah, go...@googlegroups.com
There are other options of course (setting environment variables on agent startup, or changing /etc/paths on macOS), but they require modifying the agents themselves.

Giving an absolute path to the GoCD task config is by far the easiest since it’s a single change in one place, and also a good practice since you won’t need to care about your PATH too much.

Sushma Gangaiah

unread,
Jun 3, 2021, 8:36:27 AM6/3/21
to Marques Lee, go...@googlegroups.com
Hi Marques,

The suggested method is good. But I have another hurdle, while this can be executed manually but issues while running through gocd. As my script to run "npm install" in abcd directory is 

            - exec:
                arguments:                
                - install
                command/usr/local/bin/npm
                working_directory./abcd
                run_ifpassed

According to above script its trying to search for /usr directory in abcd in which I am getting below error. Please advice

[go] Task: /usr/local/bin/npm installtook: 0.175sexited: 127
env: node: No such file or directory
[go] Task status: failed, took: 0.175s, exited: 127
[go] Current job status: failed
Regards,
Sushma

Sushma Gangaiah

unread,
Jun 3, 2021, 8:47:48 AM6/3/21
to Marques Lee, go...@googlegroups.com
Wondering why it's trying to fetch from different path,where build in the rest of the agents is going smoothly. 
Is this environment variable specific to agent?

Regards,
Sushma

Marques Lee

unread,
Jun 3, 2021, 8:57:08 AM6/3/21
to Sushma Gangaiah, go...@googlegroups.com
Hmm, that’s right npm really just wraps node. So you’ll have to change your PATH to include /usr/local/bin

You can do this in the wrapper properties for the agents.

You should be able to add:

set.PATH=/usr/local/bin:/usr/bin:...

Sriram Narayanan

unread,
Jun 3, 2021, 9:05:00 AM6/3/21
to go...@googlegroups.com, Sushma Gangaiah
On Thu, Jun 3, 2021 at 8:57 PM Marques Lee <marqu...@thoughtworks.com> wrote:
Hmm, that’s right npm really just wraps node. So you’ll have to change your PATH to include /usr/local/bin

You can do this in the wrapper properties for the agents.

You should be able to add:

set.PATH=/usr/local/bin:/usr/bin:...


I suggest moving all of that into a shell script and running commands from within that shell script. The shell script can be trialled and version controlled.

The shell script can then contain all the custom PATH settings, tweaks, etc. as needed.

 

Marques Lee

unread,
Jun 3, 2021, 9:13:05 AM6/3/21
to go...@googlegroups.com, Sushma Gangaiah
The user stated that it would be less desirable to wrap in a script.

Setting PATH through wrapper properties should work. Guessing that node and npm were installed through homebrew as these agents appear to be Mac minis, so everything is under /usr/local/bin

Sushma Gangaiah

unread,
Jun 3, 2021, 9:46:39 AM6/3/21
to Marques Lee, go...@googlegroups.com
Dear Marques,

Thanks a lot.This fixed the issue 💃

Regards,
Sushma

Marques Lee

unread,
Jun 3, 2021, 10:01:56 AM6/3/21
to Sushma Gangaiah, go...@googlegroups.com
Glad to hear it! 👍🏼
Reply all
Reply to author
Forward
0 new messages