简体   繁体   English

错误代码为0,但Jenkins作业失败

[英]Error code is 0 but Jenkins job is failure

I always get jenkins failure: 我总是詹金斯失败:

Build step 'Execute Windows batch command' marked build as failure 构建步骤“执行Windows批处理命令”将构建标记为失败

but when I put in batch command: "echo Exit Code is %errorlevel%" I get 0 code. 但是当我输入批处理命令时:“ echo退出代码为%errorlevel%”,我得到0代码。

My batch command is: 我的批处理命令是:

ELSE (
   ROBOCOPY.EXE C:\dir2\ C:\dir1\ script.bat /IS
   cd C:\dir1\
   echo Exit Code is %errorlevel%
   C:\dir1\script.bat
   echo Exit Code is %errorlevel%
   ROBOCOPY.EXE C:\dir1 C:\dir3 /E /IS /XF *.config 
   echo Exit Code is %errorlevel%
)
echo TEST

Command echo TEST is never shown. 从不显示命令回显TEST。 When I delete from batch "C:\\dir1\\script.bat" everything works fine and jenkins job is success. 当我从批处理“ C:\\ dir1 \\ script.bat”中删除时,一切正常,詹金斯工作成功。

Script bat contains only commands like: 脚本bat仅包含如下命令:

del .\\bin\\library.dll 德尔。\\ bin \\ library.dll

What do you think, the problem is with script.bat? 您怎么看,问题出在script.bat? When I add in the end of this script: EXIT /B 0 , the job is also failed. 当我在此脚本的末尾添加:EXIT / B 0时,作业也失败了。

You would have to provide us with more than the half-statement here for a definitive answer. 您必须在这里为我们提供超过一半的陈述,才能得到明确的答案。 It may be that the ) before the else is missing (it must be on the same line as the else keyword). 这可能是)在之前else丢失(它必须在同一行的else关键字)。

More likely, you are victim number 48 million of the delayed expansion problem. 您更有可能成为delayed expansion问题中的4800万受害者。 See endless examples on SO. 请参阅关于SO的无数示例。

Within a block statement (a parenthesised series of statements) , the entire block is parsed and then executed. 在块语句(a parenthesised series of statements) ,将分析整个然后执行。 Any %var% within the block will be replaced by that variable's value at the time the block is parsed - before the block is executed - the same thing applies to a FOR ... DO (block) . 解析该块时-执行该块之前-该块内的任何%var%都将由该变量的值替换-同样的情况也适用于FOR ... DO (block)

Hence, IF (something) else (somethingelse) will be executed using the values of %variables% at the time the IF is encountered. 因此,将在遇到IF时使用%variables%的值执行IF (something) else (somethingelse)

Two common ways to overcome this are 1) to use setlocal enabledelayedexpansion and use !var! 解决此问题的两种常用方法是:1)使用setlocal enabledelayedexpansion和使用!var! in place of %var% to access the changed value of var or 2) to call a subroutine to perform further processing using the changed values. 代替%var%访问的改变值var或2),以调用一个子程序使用改变的值来执行进一步的处理。

Hence, you are seeing the value of errorlevel as it existed when the (presumed) IF was parsed - before execution. 因此,您将看到解析 (假定的) IF时(执行之前)时存在的errorlevel值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM