Android – ‘node’ is not recognized as an internal or external command error with jenkins

androidcordovaJenkinsnode.jsnpm

I am trying to set up continuous code integration with the help of jenkins v1.592
I have an android hybrid code, which I'm, trying to build with jenkins.
I have set up environment variables for ANT_HOME, JAVA_HOME, ANDROID_HOME, and added then to the PATH respectively. I also have added nodejs and npm to the PATH.

ant version 1.9.2

java version 1.8.0_25

npm version 1.4.28

cordova android version 3.5.1

C:\Users\userName>path

gives

C:\Users\userName\AppData\Roaming\npm;C:\Program Files\nodejs;C:\whateverElse…

jenkins $WORKSPACE = C:\Program Files (x86)\Jenkins\jobs\myProject\workspace\

now I set my cmd prompt to jenkins workspace and execute the following commands

  cd myProject
  cordova build android

I get BUILD_SUCCESSFUL after 24 seconds

Similarly, when I go to my local jenkins server

The jenkins dashboard is shown and I have set up myProject there and
in the project configuration I have added the lines

 "cd myProject
  cordova build android" 

in the build step and saved the configuration.
When I try to build I get the following error

Started from command line by anonymous
Building in workspace C:\Program Files (x86)\Jenkins\jobs\myProject\workspace
Updating repository at revision '2014-12-02T15:20:23.437 +0530'
At revision 263
no change for repository since the previous build
[workspace] $ cmd /c call C:\Windows\TEMP\hudson3297478415472069526.bat

C:\Program Files (x86)\Jenkins\jobs\myProject\workspace>cd myProject

C:\Program Files (x86)\Jenkins\jobs\myProject\workspace\myProject>cordova build android

'node' is not recognized as an internal or external command,
operable program or batch file.
Build step 'Execute Windows batch command' marked build as failure
Archiving artifacts
Finished: FAILURE

Any help would be appreciated

The same issue exists on mac OSX

Best Regards

Best Answer

Several things can be at play here

  1. Did you add node to %PATH% through command line, or through the Windows UI? If done through UI, it can take affect immediatelly. If done through command line, it doesn't take affect until the next process spawns from shell, therefore Jenkins server restart is required.

  2. Jenkins runs as "Local System" by default on Windows. You are listing C:\Users\userName as part of your paths, i.e. a user specific path. Did you set the %PATH% for all users, or just for your user userName? If it's not set for all users (or a specific user that Jenkins runs with), then Jenkins won't see it. You can change what user the service runs as.

2a. If Jenkins is running as "Local System" user, does that account have access to C:\Users\userName?

  1. And lastly, if you set the %PATH% from command line, did you set it as a permanent entry using setx command?

In either case, from your job configuration, add a build step "Execute Windows Batch Command" and type just set (to display all environment variables) or @echo %PATH% (to see just the %PATH%) and verify that the environment is set correctly

Related Topic