运行 shell 脚本时如何在 Jenkins 中标记构建不稳定 [英] How to mark a build unstable in Jenkins when running shell scripts

查看:65
本文介绍了运行 shell 脚本时如何在 Jenkins 中标记构建不稳定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在进行的一个项目中,我们使用 shell 脚本来执行不同的任务.有些是运行 rsync 的 sh/bash 脚本,有些是 PHP 脚本.其中一个 PHP 脚本正在运行一些集成测试,这些测试输出到 JUnit XML、代码覆盖率报告等.

In a project I'm working on, we are using shell scripts to execute different tasks. Some are sh/bash scripts that run rsync, and some are PHP scripts. One of the PHP scripts is running some integration tests that output to JUnit XML, code coverage reports, and similar.

Jenkins 能够根据退出状态将作业标记为成功/失败.在PHP 中,如果在运行期间检测到测试失败,脚本会以 1 退出.其他 shell 脚本运行命令并使用这些命令中的退出代码将构建标记为失败.

Jenkins is able to mark the jobs as successful / failed based on exit status. In PHP, the script exits with 1 if it has detected that the tests failed during the run. The other shell scripts run commands and use the exit codes from those to mark a build as failed.

// :: End of PHP script:
// If any tests have failed, fail the build
if ($build_error) exit(1);

Jenkins 术语中,不稳定的构建定义为:

In Jenkins Terminology, an unstable build is defined as:

如果构建成功并且一个或多个发布者报告它不稳定,则构建不稳定.例如,如果配置了 JUnit 发布者并且测试失败,那么构建将被标记为不稳定.

A build is unstable if it was built successfully and one or more publishers report it unstable. For example if the JUnit publisher is configured and a test fails then the build will be marked unstable.

如何让 Jenkins 在运行 shell 脚本时将构建标记为不稳定而不是仅成功/失败?

How can I get Jenkins to mark a build as unstable instead of only success / failed when running shell scripts?

推荐答案

使用 Text-finder 插件.

不要以状态 1 退出(这会导致构建失败),而是:

Instead of exiting with status 1 (which would fail the build), do:

if ($build_error) print("TESTS FAILED!");

在构建后操作中启用文本查找器,设置正则表达式以匹配您打印的消息(TESTS FAILED!)并选中该条目下的如果找到则不稳定"复选框.

Than in the post-build actions enable the Text Finder, set the regular expression to match the message you printed (TESTS FAILED!) and check the "Unstable if found" checkbox under that entry.

这篇关于运行 shell 脚本时如何在 Jenkins 中标记构建不稳定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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