上篇我们通过Allure插件生成了测试report,并通过打开浏览器的方式查看图形化测试report,那要集成都Jenkins中去,并以邮件的方式发送测试report要怎么做呢?请看以下操作
一、搭建环境
1.jenkins环境搭建见《手把手教你搭建Jenkins+Jmeter+Ant自动化集成环境》中的Jenkins部分,这里不做介绍
二、在jenkins中配置插件
1.分别安装插件 Allure Jenkins Plugin 、HTML Publisher plugin
a.在Jenkins的页面中点击“系统管理”->"管理插件",搜索“allure”,在搜索结果页,选择“Allure Jenkins Plugin”进行安装。安装完成之后重启一下Jenkins。

进入插件管理界面,选择“可选插件”->在右上角过滤编辑框中写入"Allure",按回车键,然后勾选Allure,点击直接安装

b.进入插件管理界面,选择“可选插件”->在右上角过滤编辑框中写入"HTML",按回车键,然后勾选HTML Publisher,点击直接安装




重启后可在“插件管理”界面查看到已安装成功的插件和插件版本


2.添加allure执行工具
下载allure压缩文件allure-commandline.zip ,解压并添加allure路径至path环境变量

3.在Jenkins的主界面中找到并进入“(Global Tool Configuration)全局工具管理”页面

找到Allure Commandline安装 字样,点击新增Allure Commandline

点击后,在弹出下面的页面,输入Allure的命令别名和版本(这里我选择最新版本号)后,点击Apply 和Save

三、配置Job
1.在Jenkins主界面点击新建,进入如下界面,建立 jenkins 持续集成项目, 这里选择自由风格的项目,按照步骤执行操作后点击OK

2.点击OK后进入Allure Report界面,如下图所示

3.在Allure Report界面,分别配置“构建”和“构建后操作”
a.配置构建步骤:进入Allure Report界面,找到“构建”下方的“增加构建步骤”,下来选择Excute Windows batch command

b.输入如下配置步骤指令:
D:
cd \work\pytest
py.test -s -q --alluredir ${WORKSPACE}/report


原因:jenkins执行命令,会把命令生成一个批处理文件执行,而pytest命令对于批处理来说是外部命令,所以要加call表示调用。而jenkins执行windows命令,若退出代码不为0 ,则jenkins会将构建标记为失败,所以需要加上exit 0表示执行完成退出
解决方法:构建命令在py.test前面加上call,最后加上exit 0


c.在构建后操作下拉一栏选择“Allure Report”,进入“Allure Report”界面,写入保存报告的路径名称“report”,在“Properties”一栏分别写入Key和Value对应的变量值和存放测试用例文件的路径,如下图所示:

这里需要注意一点就是:执行指令生成测试报告的路径名称和保存测试报告的路径名称必须一致,不然会提示错误。如下图设置

四、查看运行结果
在Jenkins界面点击“立即构建”,会在左下角出现进度条显示,当进度条显示完成后,刷新下当前界面,可以在页面右侧看到运行结果,点击界面的“Allure Report”字样,可查看该测试用例运行的详细情况




