将Postman测试脚本与Jenkins构建服务器集成 [英] Integrate Postman test scripts with Jenkins build server
问题描述
我已经下载了POSTMAN Chrome应用程序,以便在本地开发环境中测试某些Web API.
I've downloaded the POSTMAN Chrome app in order to test some Web APIs on my local dev environment.
此外,我已经下载了适用于Postman的Newman cmd-line实用程序.
In addition, I've downloaded the Newman cmd-line utility for Postman.
有关更多信息,请参见 https://www.getpostman.com/docs/newman_intro .
See https://www.getpostman.com/docs/newman_intro for more info.
Postman应用程序运行正常,而cmd-line实用程序也运行正常.
So the Postman app is working fine, and the cmd-line utility is working too.
但是,一旦将其与我的Jenkins测试服务器集成,测试就会失败.
However, once I integrate it with my Jenkins test server, the tests are failing.
主要问题是它无法启动Newman
.
The main problem is that it's not able to launch Newman
.
在标准cmd提示符下,我可以成功运行Newman测试脚本:
In a standard cmd prompt, I can successfully run the Newman test script as :
newman -c API-Collection.json -n 3
运行n次.
然后在Jenkins
构建服务器GUI中,在执行外壳"选项下添加构建脚本.
And in the Jenkins
build server GUI, I add the build script under the "Execute Shell" option.
但找不到Newman
,因为此生成错误显示:
But it doesn't find Newman
, as this build error shows:
FailedConsole Output
Started by user anonymous
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Web Api Test1 (Team Gecko)
[Web Api Test1 (Team Gecko)] $ "C:\Program Files\bin\sh.exe" -xe C:\Windows\TEMP\hudson2522506155962538386.sh
+ newman -c C:\Users\robertjm\Documents\POSTMAN Files\Workbench-API-Collection.json -n 3 -y 1000 --exitCode 1 -o output.json -H output.html
C:\Windows\TEMP\hudson2522506155962538386.sh: newman: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
如果有人可以帮助我解决此路径问题,我将不胜感激.
If someone can assist me in resolving this path issue, I would appreciate it.
谢谢, 鲍勃
推荐答案
最终解决方案是:
1)添加构建步骤执行Windows批处理命令",并在下面添加两行:
1) Add build step "Execute Windows batch command" and add two lines below:
2)将目录更改为newman \ bin:
2) change dir to newman\bin:
cd \Users\bob\appdata\roaming\npm\node_modules\newman\bin
3)运行node newman
,而不是简单地尝试运行newman
3) run node newman
as opposed to simply trying to run newman
node newman -c "C:\\Users\\bob\\Documents\\POSTMAN Files\\Workbench-API-Collection.json"
两个棘手的部分是:
1)运行像newman -c myCollection.json
这样的纽曼无法正常工作,因为詹金斯无法像在直接Win cmd提示符下那样解析此节点模块.
1) running newman like this newman -c myCollection.json
was not working, as Jenkins could not resolve this node module as it would in a straight Win cmd prompt.
2)尝试查找Newman模块很困难,因为它隐藏在%appdata%
文件夹(即c:\ users \ bob \ $ appdata $)中.
2) Trying to locate the Newman module was difficult, as it's hidden inside %appdata%
folder (i.e. c:\users\bob\$appdata$ ).
我希望这对以后的人有所帮助.
I hope this helps someone in the future.
祝你好运.
这篇关于将Postman测试脚本与Jenkins构建服务器集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!