简体   繁体   English

在Jenkins上测试失败时,可以将Karma或Grunt配置为不退出代码1吗?

[英]Can Karma or Grunt be configured not to exit with code 1 when tests are failing on Jenkins?

We run unit and acceptance (e2e) tests on Jenkins using Karma and Grunt. 我们使用Karma和Grunt在Jenkins上进行了单元测试和验收(e2e)测试。 Karma produces JUnit reports using the karma-junit-reporter , and we've configured Jenkins to set the build as unstable (yellow) if test failures are found in these report files. Karma使用karma-junit-reporter生成JUnit报告,并且如果在这些报告文件中发现测试失败,我们已经配置Jenkins将构建设置为不稳定(黄色)。

The problem is that whenever a test fails, Karma and Grunt exits with a non-zero exit code and this makes the build failed (red). 问题是,每当测试失败,Karma和Grunt都会以非零的退出代码退出,这会使构建失败(红色)。 Can this behavior be altered? 这种行为可以改变吗?

I'd prefer not to run Grunt with --force , because I still want a failed build when the tests cannot be executed or when other tasks fail. 我不想使用--force运行Grunt,因为当测试无法执行或其他任务失败时,我仍然希望构建失败。

This seems to be a common problem with many test runners. 对于许多测试跑步者来说,这似乎是一个普遍的问题。 I myself execute my tests like this: 我自己执行这样的测试:

test-runner || true

This means the exit code of test-runner is ignored completely. 这意味着将完全忽略测试运行程序的退出代码。 If there is a problem with test-runner and it does not run at all, it probably does not produce test result xml files either, which will make the build fail because Jenkins wants to find at least one test result file. 如果test-runner出现问题并且根本无法运行,则它也可能不会生成测试结果xml文件,这将使构建失败,因为Jenkins希望找到至少一个测试结果文件。

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

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