Windows START command not working from Jenkins Pipeline

半城伤御伤魂 提交于 2019-12-10 11:17:55

问题


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


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!