gpt4 book ai didi

windows - robocopy 导致成功退出(1)

转载 作者:行者123 更新时间:2023-12-03 11:09:37 26 4
gpt4 key购买 nike

我正在尝试在 jenkins 中调用此代码

rem copy installation to output folder
set src="C:\code\EPMD\Installer\inno setup\Output"
set dst="c:/test_installs/Calibration/%version_name%"
call robocopy %src% %dst% /MIR /E /is /it

代码运行并工作,在目标文件夹中创建一个新文件。

正如文档所述,这使得 robocopy 返回 1。

然后,它调用 exit 1在内部, Jenkins 认为构建失败了。

如何“捕获”该返回值而不会使构建失败?

最佳答案

robocopy command使用退出代码(或 ErrorLevel )来指示复制操作的结果,其中值小于 8并不意味着发生了错误;你可以后转换这个 ErrorLevel :

rem /* Note the changed quotation, so the quotes do no longer become part of the variable values;
rem this does not change much in the situation at hand when you quote the values later then,
rem but it will simplify potential concatenation of multiple variable values a lot: */
set "src=C:\code\EPMD\Installer\inno setup\Output"
set "dst=c:/test_installs/Calibration/%version_name%"
rem // Now the values become quoted; regard that the superfluous `call` has been removed:
robocopy "%src%" "%dst%" /MIR /E /IS /IT
rem // This handles the exit code (`ErrorLevel`) returned by `robocopy` properly:
if ErrorLevel 8 (exit /B 1) else (exit /B 0)

如果您不想在 robocopy 之后立即退出批处理脚本,你可以这样做:

set "src=C:\code\EPMD\Installer\inno setup\Output"
set "dst=c:/test_installs/Calibration/%version_name%"
robocopy "%src%" "%dst%" /MIR /E /IS /IT
rem // Terminate the script in case `robocopy` failed:
if ErrorLevel 8 exit /B 1
rem // Here we land when case `robocopy` succeeded;
rem Do some further actions here...
rem ...
rem // Finally explicitly force a zero exit code:
exit /B 0

关于windows - robocopy 导致成功退出(1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56234411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com