Jenkins在外部可执行文件上通过或失败 [英] Jenkins pass or fail build on external executable

查看:166
本文介绍了Jenkins在外部可执行文件上通过或失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为构建过程的一部分,我编写了一个EXE,它将数据库更改推送到登台DB.

As part of my build process, I have an EXE that I wrote that pushes database changes to the staging DB.

此过程有时会遇到错误,如果是这样,我希望构建失败.如何添加EXE作为构建步骤,以便在失败时(可能会捕获到异常)我可以使构建失败并记录一些详细信息(类似于NUNit显示失败的方式)?

This process encounters errors sometimes, and if so, I would like the build to fail. How can I add the EXE as a build step so that on failure (which I could catch as an exception) I can fail the build and log some details (similar to the way NUNit shows failures)?

我还希望exe记录其他一些详细信息(例如更改内容-构建是通过还是失败).是否有任何有关如何执行此操作的文档?

I would also like the exe to log some other details (like what's changed - whether the build passes or fails). Is there any documentation to how I can do this?

我正在使用MSBuild,并且可以完全控制EXE(我写了它).我可以对其进行编码以输出所需的内容

I'm using MSBuild, and I have full control over the EXE (I wrote it). I can code it to output what I want

推荐答案

您的主要构建步骤使用的是什么? Mavent?蚂蚁?自定义脚本?有很多方法可以做到这一点,而这在很大程度上取决于.exe的设计方式,而您在OP中并未对此进行解释.

What are you using for your main build step? Mavent? Ant? Custom script? There are many ways to do it, and it highly depends on the way your .exe is designed, which you didn't explain in the OP.

最简单的方法是从下拉菜单中添加另一个构建步骤.选择执行Windows批处理命令.在其中编写批处理命令以启动.exe并捕获返回代码:

Easiest would be to add another build step from the drop-down. Select Execute Windows batch command. In there, write batch commands to launch the .exe and capture the return code:

C:\Location_of_exe\your.exe
IF NOT "%ERRORLEVEL%" == "0" (
    ECHO "Your exe failed"
    EXIT /B 1
) ELSE (
    ECHO "Your exe passed"
)

如果.exe像正常程序一样工作,则成功时它将返回退出代码0,否则将返回非零退出代码.上面的语句查找非零退出代码(表示某种失败),如果检测到该退出代码,则退出错误代码为1的批处理EXIT /B 1.反过来,这将向Jenkins指示构建步骤已失败,并且将作业标记为失败.

If your .exe works like normal programs, it will return exit code 0 when successful, else it will return a non-zero exit code. The above statement looks for non-zero exit code (indicating failure of some sort), and if detected will exit the batch with error code 1 itself EXIT /B 1. This in turn will indicate to Jenkins that the build step has failed, and will mark the job failed.

再次,这很大程度上取决于您的.exe正确无误,并在失败时返回非零退出代码.

Once again, this highly depends on your .exe being correct and returning non-zero exit code on failure.

再次,我也希望exe记录其他细节"完全取决于您的.exe

As far as "I would also like the exe to log some other details", once again, depends entirely on your .exe

  • 对于不同的故障,它是否返回不同的退出代码? -如果是这样,可以轻松地修改上面的代码以捕获所有可能性并相应地在日志中显示错误

  • Does it return different exit codes for different failures? - If so, the code above can be easily modified to capture all possibilities and display error in log accordingly

这是一个在控制台中显示不同错误的命令行.exe吗?如果是这样,那么从批处理中调用它将自动在Jenkins日志中显示错误.如果您的.exe没有返回正确的退出代码,则也可以使用这种方法.您可以捕获命令行输出,然后使用findstr在此处搜索特定的输出行以确定成功或失败

Is it a command line .exe that display different errors in console? If that's so, then calling it from the batch will automatically display the errors back in Jenkins log. You can also use this approach if your .exe does not return correct exit codes. You can capture the command line output and use findstr to search for specific output lines there to determine success or failure

如果您的.exe是GUI应用程序,并且没有生成正确的退出代码,那么您将无法判断它是成功还是失败(以及失败的原因)

If your .exe is a GUI application, and does not generate correct exit codes, then you got no way of telling if it was successful or it failed (and what failed)

如果您确定答案是我,我将对其进行更新.

I will update this answer if you identify which one it is.

这篇关于Jenkins在外部可执行文件上通过或失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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