项目介绍
- 接口功能测试应用:http://www.weather.com.cn/data/cityinfo/<city_code>.html
- 测试功能:获取对应城市的天气预报
- 请求方法:Get
- 压测脚本开发工具:jmeter
- 源码脚本位置:https://github.com/shifengboy/iInterface_python/blob/master/jmx/iInterface.jmx
源功能点
- 将Jmeter压测任务集成到Jenkins
- 通过Jenkins运行Jmeter任务
- 在Jenkins上展示Jmeter压测报告
项目配置
1、新建一个自由风格任务
![](https://img-blog.csdnimg.cn/img_convert/39e3da32abeb697fa992db6907537ad2.png)
git源码库地址">2、添加git源码库地址
可自行添加自己的代码厂库地址
![](https://img-blog.csdnimg.cn/img_convert/49795a4d6d7899d25ee2af409d340d61.png)
3、添加自动化压测运行代码
![](https://img-blog.csdnimg.cn/img_convert/94a609b412e55ff3afcb387236061b85.png)
添加如下构建命令
. ~/.bash_profile
cd iInterface_python/jmx
sh auto_stress_test.sh
该命令可根据自己的实际项目进行添加
4、导出压测报告
在Post-build Actions(构建后操作)中添加 Publish HTML reports
![](https://img-blog.csdnimg.cn/img_convert/cf34486988976834fa79abcf33d9fdd9.png)
需要注意的是,Jenkins出于的全策略的原因,会限制js脚本的渲染,默认生成的报告打开后会有样式问题,如下图:
![](https://img-blog.csdnimg.cn/img_convert/2b9445c4bcf2c0f2ff9d756db824bd96.png)
需要解除该限制
具体解除限制的方法有
1、临时解决方案(重启Jenkins失效):在系统管理->脚本命令行:
![](https://img-blog.csdnimg.cn/img_convert/13266f38fcb46787aeb27a52e3d264e8.png)
执行:
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
点击运行
![](https://img-blog.csdnimg.cn/img_convert/45d2bb99a44dff50dbefc617456034c0.png)
2、永久解决方案:
1).安装Groovy Postbuild 插件
该插件可能不是很好下载,若出现无法下载的情况,可访问我的百度网盘 链接: https://pan.baidu.com/s/1qZ5csambF2yYyzpywO871Q 提取码: xh6d 进行下载后,放在Jenkins的plugins目录下重启即可
2).进入任务->配置->构建->增加构建步骤 Groovy Postbuild,Groovy Script填写:System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", ""),保存
![](https://img-blog.csdnimg.cn/img_convert/90ad2ca45a3f1b068072dc56f56451c7.png)
5、发送邮件
在Post-build Actions(构建后操作)中添加 Editable Email Notification
![](https://img-blog.csdnimg.cn/img_convert/ac827b9dbf40780af69a1b346fa84b91.png)
注:Editable Email Notification插件安装后需要系统管理-系统配置 Extended E-mail Notification选项中进行设置好后才能正常使用
![](https://img-blog.csdnimg.cn/img_convert/60905e8801eb118b4f96c95fa9e4cb76.png)
![](https://img-blog.csdnimg.cn/img_convert/d89bcdcb5de9d036c8c0f1bc2f6ab8fb.png)
![](https://img-blog.csdnimg.cn/img_convert/991fb60495b26ace441e33cb323814be.png)
设置完成后,保存,构建
![](https://img-blog.csdnimg.cn/img_convert/822b5a9a3395a5043189d2805669dede.png)
报告:
![](https://img-blog.csdnimg.cn/img_convert/99d2933f8239eae1f5f5e21349665718.png)
邮件:
![](https://img-blog.csdnimg.cn/img_convert/07ee71008182b573b21f8630eaff0d90.png)