詹金斯工作失败 [英] Failing a jenkins job

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

问题描述

我有一个.Jar文件,它将在运行时将数据加载到数据库中.我已经计划通过詹金斯(Jenkins)来从事这项工作.当我在詹金斯执行作业时,它将成功运行.JAR.但是,请说作业中是否存在空指针异常,并且该异常未成功完成.即便如此,詹金斯也说这项工作已经通过".如果作业执行过程中出现问题,如何使作业失败?

I have a .Jar file that will just load data into database when it's run. I have scheduled to run this job via Jenkins. When I execute the job in Jenkins it runs the .JAR successfully. However say if there is a null pointer exception in the job and it did not complete successfully. Even then Jenkins says that job has "Passed". How do I fail the job if there is an issue during the job execution?

推荐答案

@Corey的解决方案很好.而且,如果您不想编写JUnit测试并在Jenkins中提供支持,则可以执行他先前提到的功能:捕获空指针异常(确实,在您的应用程序中只有一个顶级捕获),并且调用API并返回返回代码:

@Corey's solution is good. And if you don't want to write a JUnit test and support it in Jenkins, you can just do what he alluded to earlier: catch the null-pointer exception (really, just have a top-level catch in your app), and call the API to exit with a return code:

try {
    myCode.call();
catch (Exception e) {
    System.out.println("An exception was caught at the top level:" + e);
    System.exit(-1);
}

这篇关于詹金斯工作失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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