环境搭建:linux上安装newman,部署好jenkins linux上war包方式安装Jenkins
以下实现jenkins上执行postman测试脚本:
1.新建一个自动风格的job
2.构建-增加构建步骤-执行shell
source /etc/profile cd /home/postman_script newman run v3.x审方-0-用户登录和开始审方.postman_collection.json -e 10.1.1.71.postman_environment.json --reporters cli,json,html,junit --reporter-json-export report-json.json --reporter-html-export report-html.html --reporter-junit-export report-xml.xml
注:需要将postman脚本事先上传到服务器
[root@ipha-dev71-1 postman_script]# cd /home/postman_script/ # postman脚本所在路径 [root@ipha-dev71-1 postman_script]# ll total 8 -rw-r--r-- 1 root root 372 Aug 10 23:13 10.1.1.71.postman_environment.json -rw-r--r-- 1 root root 3294 Aug 10 23:13 v3.x审方-0-用户登录和开始审方.postman_collection.json
3.查看构建结果
以下步骤非必须
4.将测试结果以文件格式保存(需安装插件HTML Publish)
构建后操作-增加构建后操作步骤-Publish Html Reports
HTML directory to archive 填写相对于工作空间的html报告所在的目录,需要填写真实存在的目录名称(如上图中的reports,需要自己事先创建,否则构建时会报错)
Index page[s] 报告目录中提供链接的文件,需要填写一个已经存在的html文件
Report title 报告标题
=================以上转载自爱打盹的猫猫================
下面是构建过程中遇到的坑
练手项目配置shell脚本:
source /etc/profile
cd /home/xx
newman run api_test.postman_collection.json -r html --reporter-html-export index.html
执行完成之后Jenkins报错如图:
翻译过来是说这个文件拷贝失败,网上查了一堆,说需要安装html的插件,但是在Linux安装的过程中,遇到一堆依赖需要安装,走了很多弯路
后来直接拿命令执行后,生成了html文件,说明newman的命令没问题,导出文件收集时路径不对,改下路径就行
source /etc/profile
cd /home/xx
newman run api_test.postman_collection.json -r html --reporter-html-export /var/lib/jenkins/workspace/Postman_api_test/reports/index.html
执行成功