on a Windows machine, I have setup a very simple pipeline in Jenkins that does the following:
clone a git repository,
install the packages,
run the app via "pm2 start command"
Below is the entire pipleline script :
node {
stage('dev'){
git credentialsId: 'my-credentials', url: 'git@myurl.git'
bat 'npm install'
bat 'pm2 start src\\index.js --name myapp'
}
}
Everything works fine except running the pm2 command. The output error says :
'pm2' is not recognized as an internal or external command, operable program or batch file.
However, I can easily run the exact same PM2 command via CMD, I have tried putting the last line command into a .bat file and asked jenkins to execute it, and get the same error.
Jenkins couldn't access the PM2
that was installed on the Windows machine globally that is due to the fact that Jenkin was running as the system (root) user while pm2 was running with the local user. I had to include PM2
in the package.config file of the project and then call it from the node_module folder.
\node_modules\.bin\pm2 start src\\index.js --name myapp