Jenkins没有正确解释Windows批处理命令

时间:2016-09-14 16:45:53

标签: windows batch-file jenkins

嘿伙计们,我确实有以下批处理文件/命令:

setlocal enableextensions enabledelayedexpansion
IF EXIST C:\myapp (
set /p pid =< C:\myapp\RUNNING_PID
echo !pid!
taskkill /PID !pid! /F
DEL RUNNING_PID
rmdir C:\myapp /s /q
)
endlocal
mkdir C:\myapp
xcopy /E "C:\Program Files  (x86)\Jenkins\workspace\myapp\target\universal\myappDist\myapp-1.0"  C:\myapp
start java.exe -Dpidfile.path=C:\myapp\RUNNING_PID -Dhttp.port=3000 -cp C:\myapp\lib\* play.core.server.NettyServer

但是,Jenkins没有正确解释它。它总是尝试执行以下操作:

setlocal enableextensions enabledelayedexpansion 
IF EXIST C:\myapp (
set /p pid = 0<C:\myapp\RUNNING_PID  
echo !pid!  
taskkill /PID !pid! /F  
DEL RUNNING_PID  
rmdir C:\lexia /s /q 
) 

剩下的代码行再次正确解释。我不知道这里发生了什么。

希望有人能给我一个提示。

提前谢谢!

1 个答案:

答案 0 :(得分:1)

我首先要替换它:

setlocal enableextensions enabledelayedexpansion
IF EXIST C:\myapp (
set /p pid =< C:\myapp\RUNNING_PID
echo !pid!
taskkill /PID !pid! /F
DEL RUNNING_PID
rmdir C:\myapp /s /q
)
endlocal

使用:

setlocal enableextensions disabledelayedexpansion
IF EXIST C:\myapp\ (
    set/p pid=<C:\myapp\RUNNING_PID
    echo %pid%
    taskkill /PID %pid% /F
    DEL RUNNING_PID
    rmdir C:\myapp /s /q
)