我正在Jenkins运行带有nosetests的测试用例.一般来说,它将有100个测试用例,我想在少于20个测试用例失败时标记构建不稳定.如果超过20个测试用例失败,则标记构建失败.
我跑的命令:
nosetests test.py --tc-file config.yml --tc-format yaml
Run Code Online (Sandbox Code Playgroud)
首先,我试图将构建的状态更改为Unstable但它仍然失败.
我使用的groovy脚本:
manager.addWarningBadge("Thou shalt not use deprecated methods.")
manager.createSummary("warning.gif").appendText("<h1>You have been warned!</h1>", false, false, false, "red")
manager.buildUnstable()
Run Code Online (Sandbox Code Playgroud)
执行前两行代码,但作业仍标记为失败.
我的jenkins配置有什么问题吗?或者groovy postbuild插件不适用于nosetest?
这是控制台输出:
FAILED (failures=2)
Build step 'Execute shell' marked build as failure
Build step 'Groovy Postbuild' marked build as failure
Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)
Dav*_*ner 11
正如DevD概述的那样,FAILED构建状态比构建状态更重要UNSTABLE.这意味着调用manager.buildUnstable()或manager.build.setResult(hudson.model.Result.UNSTABLE)在步骤失败后仍将保留构建结果FAILED.
但是,您可以UNSTABLE使用反射覆盖失败的构建结果状态:
manager.build.@result = hudson.model.Result.UNSTABLE
Run Code Online (Sandbox Code Playgroud)
下面的示例遍历构建日志行,查找特定的正则表达式.如果发现它将更改(降级)构建状态,则添加徽章并附加到构建摘要.
errpattern = ~/TIMEOUT - Batch \w+ did not complete within \d+ minutes.*/;
pattern = ~/INSERT COMPLETE - Batch of \d+ records was inserted to.*/;
manager.build.logFile.eachLine{ line ->
errmatcher=errpattern.matcher(line)
matcher=pattern.matcher(line)
if (errmatcher.find()) {
// warning message
String errMatchStr = errmatcher.group(0) // line matched
manager.addWarningBadge(errMatchStr);
manager.createSummary("warning.gif").appendText("<h4>${errMatchStr}</h4>", false, false, false, "red");
manager.buildUnstable();
// explicitly set build result
manager.build.@result = hudson.model.Result.UNSTABLE
} else if (matcher.find()) {
// ok
String matchStr = matcher.group(0) // line matched
manager.addInfoBadge(matchStr);
manager.createSummary("clipboard.gif").appendText("<h4>${matchStr}</h4>", false, false, false, "black");
}
}
Run Code Online (Sandbox Code Playgroud)
注意:这会迭代每一行,因此假设这些匹配是唯一的,或者您希望为每个匹配的行追加徽章和摘要!
构建后的结果是:
Build step 'Execute Groovy script' marked build as failure
Archiving artifacts
Build step 'Groovy Postbuild' changed build result to UNSTABLE
Email was triggered for: Unstable
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8334 次 |
| 最近记录: |