Jenkins build step fails when calling "npm" on mac-os-x Yosemite
Asked Answered
C

2

9

Before I start, I want to say that I already checked these answers:

Jenkins build step fails on 'npm install <whatever>'

Jenkin's build failing on npm install

Now, I'm dealing with this issue for a while already and thus I tried a bunch of stuff.

Firstly, I installed node + npm via homebrew. A simple $ node -v and $ npm -v echoed the version v0.10.36 for node and v2.3.* for npm, which also means I HAVE THEM IN THE PATH and they work while called in the terminal.

Simply adding node -v; npm -v to the execute shell in Jenkins didn't do it. After a bit of tinkering I copied what $: which node yielded in the terminal to the above mentioned script, which now looked like this: /usr/local/bin/node and apparently that worked. The Jenkins build succeeded and 'node-v0.10.36' was proudly displayed in the console output.

When doing the same for 'npm' which happened to be /usr/local/bin/npm --version the computing gods weren't so merciful anymore. A big 'env: node: No such file or directory' error was thrown this time and the whole build failed.

The actual command that fails is $ /bin/sh -xe /var/folders/wr/g_dl81tn5_x0t_yz3jw602cr0000gn/T/hudson8770480548136671253.sh and "surprisingly" when I run the same command in the terminal it succeeds.

I also uninstalled the homebrew node & npm versions and installed them afterwards via the package manager. Same results.

Ultimately I also did this: https://gist.github.com/DanHerbert/9520689, with no luck.

Notes:

  • I'm running Jenkins 1.613 and tried with 1.5**
  • I didn't create a "Jenkins" specific user but instead I'm using the admin. This happens to be the same user that Jenkins runs, since the who am i command inside the executable script yields the admin's user name.
  • sudo'ing doens't help
  • I'm also running the whole thing in a Virtual Environment - vagrant
  • I'm not running Jenkins as a deamon, as it's conflicting with xtools, but as a simple process
  • I also tried out jenkins-node plugin with various configs (can detail if needed)

Thanks a lot for your help, and let me know if you need any other info, screenshots, logs, etc.

Cleareyed answered 12/5, 2015 at 0:1 Comment(0)
C
23

I found my own solution. The problem was that the PATH although visible in shell was not exported for the Jenkins job, and so, the first workaround, as found here, was to export it in the actual script like so:

enter image description here

but this feels like a hack!

The right and elegant solution is to use Jenkins EnvInject Plugin and export the path in the added Properties content textarea on the configuration page, like so:

enter image description here

Cleareyed answered 13/5, 2015 at 1:27 Comment(4)
This is cleary more elegant than the first solution. +1Debunk
Copy-paste-able: PATH=/sbin:/usr/sbin:/usr/bin:/usr/local/binRoach
@Gabriel C. Troia: i have same problemBiebel
[ios] $ /bin/sh -xe /var/folders/sj/01rfz4rx1ws_smjvggb_klzw0000gq/T/jenkins4554679135651179022.sh + /usr/local/bin/cordova platform rm ios --no-telemetry --no-update-notifier env: node: No such file or directory Build step 'Execute shell' marked build as failure Finished: FAILURE is it what i can add now ?Biebel
C
0

Manage Jenkins -> Configure System -> Global properties -> Environment variables

enter image description here

Circumlocution answered 22/6, 2022 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.