jenkins - 詹金斯管道如何根据测试结果的百分比更改阶段结果
问题描述
jenkins pipeline junit 使用一个奇怪的指标来衡量工作的健康状况,
https: //www.jenkins.io/doc/pipeline/steps/junit/如果一个测试失败将标记阶段/工作不稳定
如果 20% 的测试失败,是否可以告诉阶段,然后将其标记为不稳定,否则成功?
解决方案
我创建了一个读取结果 xml 的 python 脚本,并获得了失败的测试和总数,并在 python 脚本中而不是从 cli 中运行 pytest,这样我就可以控制错误代码。因为如果某些测试失败,junit插件会将它标记为不稳定,因为错误代码不是零,所以我的脚本
pytest_result = pytest.main([my tests, "--junitxml", f"{args.reports_folder}/xml/*name*.xml", "-o", "junit_suite_name=*name*"] )
使用 import xml.etree.ElementTree as ET 解析 xml 以获得失败的数量和测试的总量
percentage_fail = (failed_tests/total_tests)*100
在我将其与阈值进行比较之后
if percentage_fail > threshold:
raise SystemExit(1)
else:
print("All test working")
raise SystemExit(0)
如果变为“不稳定”,junit 将不允许您更改构建的状态,诀窍是控制运行测试产生的错误代码。在将 report.xml 传递给junit之前
推荐阅读
- python - 我无法使用“pip install dronekit”安装dronekit
- python - Python-SciPy Voronoi 图的准确性
- docker - docker-credential-desktop 未安装或在 PATH 中不可用
- tensorflow - 张量已处置
- python - “RegisterForm”对象没有属性“is_valid”
- r - 如何在没有用户输入的情况下过滤、选择和交互反应数据框?Shiny、Rmarkdown 和 Flexdashboard
- css - 使用偏移路径的 svg 动画与预期不同
- java - Java中的滚动文本
- mongodb - deno中的mongo插件在docker中崩溃
- java - 绘制带有线条的圆圈并检查鼠标是否在圆圈内 - Java Graphics- Geometry