即使在BAT脚本中成功执行了ROBOCOPY命令,JENKINS作业也会失败

时间:2017-12-26 06:39:01

标签: batch-file jenkins robocopy

我正在通过jenkins执行Windows bat脚本。批处理文件提供了所需的输出,但构建失败。我的批处理文件是..

cd /d D:\\Bank\\Member\\ID

if %errorlevel% neq 0 exit /b %errorlevel%

mkdir OTP

if %errorlevel% neq 0 exit /b %errorlevel%

robocopy C:\Corporate D:\\Bank\\Member\\ID\ /E /XF  *.bat

if %errorlevel% neq 1 exit /b %errorlevel%

cd /d D:\\Bank\\Staff\\ID

ROBOCOPY在大量复制文件后提供退出代码1。
但是JENKINS失败并且给予以下错误:

Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE

如果robocopy退出代码1,我希望构建成功。

3 个答案:

答案 0 :(得分:2)

我最好的建议是使用jenkins-pipeline,try / catch块,尽可能少地使用bat命令(或根本不使用)。

但考虑到你的情况,也有一个简单的解决方案:只需将字段“ERRORLEVEL设置为不稳定”设置为1(或其他合适的数字)。如果单击“执行Windows批处理命令”块下的“高级”按钮,则会出现该字段:

enter image description here

此方法会将您的构建检查为“不稳定”,但会继续执行。

答案 1 :(得分:0)

As mentioned here,要检查的第一个标准是用于运行Jenkins的帐户。 键入services.msc以打开Windows服务并查找Jenkins服务。

使用您自己的帐户代替“本地服务帐户”:这将避免任何正确的问题。

但是:其他标准是显示错误代码 正如mentioned here

  

所有退出代码最多为'3'都没问题。

所以在robocopy之后,您可以添加:

@echo robocopy exit code: %ERRORLEVEL%
@if %ERRORLEVEL% GTR 3 ( echo robocopy ERROR )
@if %ERRORLEVEL% GTR 3 ( exit %ERRORLEVEL% )
@set ERRORLEVEL=0
REM at the end:
exit /b 0

这将确保Jenkins不会使批处理步骤失败,即使robocopy的原始错误级别为1。

答案 2 :(得分:0)

请使用以下内容以避免:

add_action( 'woocommerce_email_before_order_table', 
'bbloomer_add_content_specific_email', 20, 4 );

function bbloomer_add_content_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
    if ( $email->id == 'customer_completed_order' ) {
        echo '<p class="email-text-conditional">Thank you for your order with Adventure Clues, we have sent your recipient the gift card’</p>';
    }
}

即使robocopy返回非零错误级别,上面将继续jenkins构建。即使在成功复制之后,Robocopy也不会因各种原因返回0,因为它比较了两个文件夹。请查找它的返回码以了解更多详情

相关问题