如何使詹金斯失败的Windows批处理命令失败? [英] How to make jenkins fail at a failing windows batch command?

查看:262
本文介绍了如何使詹金斯失败的Windows批处理命令失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jenkins中使用了一些Windows批处理命令,其中每个命令都可能失败.为了使jenkins作业在每个步骤上失败,这些批处理命令如下所示:

I use some windows batch commands in jenkins, where each of the commands could fail. In order to make the jenkins job fail on each step, these batch commands look like follows:

net use m: \\%IP_ADDRESS%\Whatever %PASSWORD% /user:%USERNAME%
if ERRORLEVEL 1 exit 1
mkdir m:\Install
if ERRORLEVEL 1 exit 1
copy /b %LOCAL_TEMP%\%INSTALLER_EXE% m:\Install\%INSTALLER_EXE% 
if ERRORLEVEL 1 exit 1
net use m: /D
if ERRORLEVEL 1 exit 1

换句话说:我似乎要检查每个批处理命令是否失败,然后在必要时以错误代码1退出.有没有更有意义/更方便/更好的方法来实现这一目标?

In other words: I seem to check every single batch command if it has failed, and then to exit with errorcode 1 if neccessary. Is there a more senseful/convenient/better way to achieve this?

如果我不检查每个步骤并退出,jenkins将执行以下批处理命令.

If I do not check every single step and exit, jenkins will execute the following batch command.

推荐答案

遗憾的是,您无法批量激活bash中的-e这样的标志,该标志会在任何不为0的返回代码上退出.但是,您可以使用逻辑or跳转到退出标签,如下所述: https://stackoverflow.com/a/8965092/2003420

Sadly in batch you cannot activate a flag like the -e in bash that would exit on any return code that is not 0. However you could use a logical or to jump to an exit label as described here: https://stackoverflow.com/a/8965092/2003420

这篇关于如何使詹金斯失败的Windows批处理命令失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆