Jenkins+Linux+httprunner+allure持
第一步--Linux基础环境准备
Python
httprunner
jdk
allure
未在Jenkins集成构建时,在Linux上可以跑通流程。jdk和allure可在Linux安装然后在Jenkins配置,或者都在Jenkins下载安装,会自动配置。
第二步--Jenkins安装Allure Jenkins Plugin和Email Extension Plugin插件
Allure Jenkins Plugin是集成到Jenkins的allure插件,可以省略由json文件转为html报告的命令
Email Extension Plugin 是发送邮件的Jenkins插件


第三步--Jenkins配置全局工具
-
进入Jenkins - 系统管理 - 全局工具配置 - JDK - JDK安装 - 新增JDK, 输入JDK别名与已安装的JDK在上的JAVA_HOME,如下:
image.png
若是没有安装JDK或者JDK不是你想要的版本,可以通过参考
image.png
2.安装allure--进入Jenkins - 系统管理 - 全局工具配置 - Allure Commandline -
进入Jenkins - 系统管理 - 全局工具配置 - Allure Commandline - 新增 Allure Commandline。 输入别名、勾选自动安装、选择Allure的版本, 构建Job时会自动安装Allure到Jenkins/toorl目录下
image.png
当然你可以选择配置已安装的allure环境
image.png
PS:由此可见,jdk和allure可以在Linux安装然后在Jenkins配置,也可以直接使用Jenkins下载安装。本项目配置:jdk是默认的没有配置过,allure是Jenkins自动下载安装的
第四步--Jenkins配置环境变量
在Jenkins构建时有时会报错命令找不到command no found
,这是因为Jenkins没有配置环境变量
Linux输入命令echo $PATH

然后在进入Jenkins, 系统管理 - 系统配置-全局属性,配置PATH

PS:如果Linux环境变量有更新,Jenkins的也要同步修改
第五步--发送邮件的相关配置
通过系统管理→系统设置,进行邮件配置:





附上邮件模板
<h1><center><font>以下是Jenkins自动发送的邮件,请勿回复!</font><center></h1>
<h3><center><font color="red">allure报告在线查看or下载allure-report.zip用firefox离线查看,测试用例见附件</font><center></h3>
<br>
<hr>
<br>
项目描述:${JOB_DESCRIPTION}<br>
<br>
<hr>
项目名称:$PROJECT_NAME<br>
构建编号:$BUILD_NUMBER<br>
构建状态:$BUILD_STATUS<br>
触发原因:${CAUSE}<br>
构建地址:<A HREF="${BUILD_URL}">${BUILD_URL}</A><br>
构建日志地址:<A HREF="${BUILD_URL}console">${BUILD_URL}console</A><br>
系统allure测试报告:<A HREF="${PROJECT_URL}${BUILD_NUMBER}/allure">${PROJECT_URL}${BUILD_NUMBER}/allure</a><br>
<hr>
${JELLY_SCRIPT}
第六步---项目job配置
新增一个自由风格的job




构建后自动发送测试邮件

遇到的问题汇总
1、xxx command no found 构建报错命令不存在,原因是需要在Jenkins配置环境变量,上面有提到
2、Jenkins Build step 'Execute shell' marked build as failure
解决办法:第一行加上#!/bin/bash
,网上都是这个答案,我试了都不行,最终在最后一行加上exit 0
就搞定了
3、Build step 'Allure Report' changed build result to UNSTABLE, 构建成功Alure report将构建标记为不稳定
存在执行失败的测试用例时,构建后操作 - Allure Report将构建标记为不稳定; 不存在失败的测试用例则不会标记为不稳定(不需理会)
参考
Jenkins集成allure报告 http://www.360doc.com/content/20/1213/21/13328254_951329740.shtml
Jenkins发送邮件 https://www.cnblogs.com/imyalost/p/8781759.html