I have following code in my script.
echo Trying to kill all node processes.
taskkill /f /im node.exe
echo Running the application...
start npm run prod
echo Success...
The script runs fine if I open a command prompt and run it from there but it doesn't start the npm run
process when I run it from Jenkins pipeline.
Strange thing is the build gets success.
Can anyone help me solve this riddle? Thanks. Update - 1 This is the output in Jenkins.
up to date in 23.58s
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deployment)
[Pipeline] bat
[ABC Pipeline] Running batch script
*************************************
Build Started
@author:
*************************************
Trying to kill all node processes.
ERROR: The process "node.exe" not found.
Running the application...
Success...
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Automation Testing)
[Pipeline] echo
Testing...
[Pipeline] echo
Tests passed!
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Update - 2 The npm file extension is .cmd and Windows 10 with Jenkins 2.89.4
Windows services are not able to open new console windows but START
is doing exactly this. So if you are running Jenkins as a service, this won't work. However, your script should work fine if you simply skip the START
command. Just npm run prod
should be enough.
EDIT:
OK, here is a workaround: if you really need to use the start command, you could create a task with the task scheduler. Righ in there you can put any batch code you want or just point it to a bat file. Use Schtasks /run /TN TaskName
to execute your task from Jenkins.
来源:https://stackoverflow.com/questions/49025062/windows-start-command-not-working-from-jenkins-pipeline