简体   繁体   English

如果没有运行测试,如何使Jenkins构建失败?

[英]How to fail Jenkins build if no tests were run?

We are running TestNG tests using Gradle on Jenkins . 我们正在使用Jenkins Gradle运行TestNG测试。

Job configuration: 工作配置:
Build section -> Invoke Gradle Script -> Use Gradle Wrapper -> Tasks: 构建部分 - >调用Gradle脚本 - >使用Gradle Wrapper - >任务:

clean test -Dgroups=myTestNGTestGroupName

In Jenkins Console Output I can see the logs from execution of gradlew.bat with specific parameters (one of them is -Dgroups=myTestNGTestGroupName )). Jenkins控制台输出中,我可以看到执行带有特定参数的gradlew.bat的日志(其中一个是-Dgroups=myTestNGTestGroupName )。

We have quite a lot of Jenkins jobs and automation Selenium tests. 我们有很多Jenkins工作和自动化Selenium测试。
Since that on daily basis we are checking only failed jobs. 因为每天我们只检查失败的工作。

During refactoring tests TestNG group name may be changed or typo may occur. 在重构测试期间,可能会更改TestNG组名称或可能出现拼写错误。
If you changed the test group name in test repository and forgot to update Jenkins job: 如果您更改了测试存储库中的测试组名称并忘记更新Jenkins作业:
0 tests are executed and job is still passing ( build is successful ). 执行0测试并且作业仍在传递( 构建成功 )。

How can I tell Jenkins to mark build as non-successful if no tests were executed? 如果没有执行测试,我如何告诉Jenkins将构建标记为不成功?

TestNG generates testng-results.xml file every time after test run 每次测试运行后, TestNG生成testng-results.xml文件
(even if 0 tests were executed). (即使执行了0次测试)。

We can analyze this file. 我们可以分析这个文件。 The simplest solution which I found is using Text-finder Plugin 我发现最简单的解决方案是使用Text-finder插件
(which in my case was already added to Jenkins ) (在我的情况下已经添加到Jenkins

I added Jenkins Text Finder in Post-build Actions as follow: 我在Post-build Actions添加了Jenkins Text Finder ,如下所示: 文本取景器,插件

How it looks in Jenkins Console Output logs: 它在Jenkins控制台输出日志中的外观:

BUILD SUCCESSFUL

Total time: 42.105 secs
Build step 'Invoke Gradle script' changed build result to SUCCESS
Archiving artifacts
Checking <testng-results skipped="0" failed="0" total="0" passed="0">
c:\jenkins\workspace\my-job-name\build\reports\tests\testng-results.xml:
<testng-results skipped="0" failed="0" total="0" passed="0">
Build step 'Jenkins Text Finder' changed build result to UNSTABLE
...
Finished: UNSTABLE

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

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