如何用建木CI生成Allure报表
听说,有趣的灵魂万里挑一,好看的皮囊千篇一律🙄️,建木 CI + Allure测试框架真是好看又好用!!
比起TestNG、ReportNG自带的测试报告,Allure框架生成的测试报告颜值大大提升!不过使用时需要安装Allure和Java环境,稍显繁琐,这里介绍一下如何使用建木CI快速生成Allure报表文件。
Allure介绍: Allure框架是一款轻量级,灵活的开源测试报告框架,它支持绝大多数测试框架, 例如TestNG、Pytest、JUint等。它简单易用,易于集成。
Allure界面展示:

前期准备
生成步骤
这里介绍一下Java和Python项目使用建木CI生成Allure报表
1.生成Allure测试报告数据
建木CI先通过 获取项目仓库,然后再通过 使用不同的工具生成测试报告数据
Java项目示例
# clone 项目
git_clone:
type: git_clone:1.2.0
param:
remote_url: https://github.com/allure-examples/allure-junit5-maven.git
# 通过maven生成Allure测试报告数据
maven-test:
image: maven:3.8.4-amazoncorretto-8
environment:
project: ${git_clone.git_path}
script:
- cd $PROJECT
- mvn test
Python项目示例
# clone 项目
git_clone:
type: git_clone:1.2.0
param:
remote_url: https://github.com/allure-examples/allure-python-pytest.git
# 通过pytest生成测试报告数据
pytest:
image: python:3.8-slim-buster
environment:
project: ${git_clone.git_path}
script:
- cd $PROJECT
- pip install allure-pytest || true
- pytest --alluredir=allure-results
2.生成Allure报表
Allure测试报告数据为json数据,为了方便查看和统计,需要使用 来生成Allure报表
allure_report:
type: allure_report:1.0.1
param:
# 该路径为生成测试报告数据的文件路径
allure_results_path: ${git_clone.git_path}/allure-results
待流程执行完成后,Allure报表就已经生成完毕了, 的输出参数为生成的报表的文件路径

如果你配置了查看allure-report报表的服务,接下来可以使用 来替换allure- report报表文件
如果你想保存报表文件,也可以使用 、 等节点上传到对应的文件服务器中
灵活选择合适的节点,甚至你还可以自定义节点,完成一些自定义功能😃,

完整DSL示例
Java项目
name: allure-java
pipeline:
git_clone:
type: git_clone:1.2.0
param:
remote_url: https://github.com/allure-examples/allure-junit5-maven.git
maven-test:
image: maven:3.8.4-amazoncorretto-8
environment:
project: ${git_clone.git_path}
script:
- cd $PROJECT
- mvn test
- ls
allure_report:
type: allure_report:1.0.1
param:
allure_results_path: ${git_clone.git_path}/allure-results
Python项目
name: allure-python
pipeline:
git_clone:
type: git_clone:1.2.0
param:
remote_url: https://github.com/allure-examples/allure-python-pytest.git
pytest:
image: python:3.8-slim-buster
environment:
project: ${git_clone.git_path}
script:
- cd $PROJECT
- pip install allure-pytest
- pytest --alluredir=allure-results || true
allure_report:
type: allure_report:1.0.1
param:
allure_results_path: ${git_clone.git_path}/allure-results
本文为OSCHINA博主「metting」的原创投稿文章,转载请联系授权。