forever run for node.js using jenkins on windows

2.3k views Asked by At

I am trying to run a forever command for a node.js script to run it in background. My complete command is

"C:/Users/Administrator/AppData/Roaming/npm/forever.cmd" -c "C:/Program Files/nodejs/node.exe" start app.js

This works fine when I ran it on command prompt directly. However when i put it as build step in jenkins I always get the following error

C:\Program Files (x86)\Jenkins\workspace\apps>"C:/Users/Administrator/AppData/Roaming/npm/forever.cmd" -c "C:/Program Files/nodejs/node.exe" start app.js 
'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

PATH on the machine is correctly set and include path to the node application. This is confirmed as command runs successfully when run locally on the slave machine without giving absolute path. Also I have provide the path to node executable in the command itself using -c option in case it does not pick up from PATH variable.

Not sure if this may be because jenkins run things on window using JVM client?

Any suggestion to resolve this.

Thanks Manoj

1

There are 1 answers

1
Slav On

Changes to PATH (such as those done after installing software like node) are not picked up by processes that were already running at the time of installation.

These processes (Jenkins process, and the Slave processes on remote machines, in this case) need to be restarted after the installation, in order to inherit the newly modified PATH.

When you test by login in remotely and running commands manually, your login session command prompt is newly created, thus inherits the new PATH and your tests work, however a Jenkins Slave process that hasn't been restarted since the installation will not have the new PATH