将 Postman 测试脚本与 Jenkins 构建服务器集成脚本、服务器、测试、Postman

2023-09-08 08:51:38 作者:心酒为友

I've downloaded the POSTMAN Chrome app in order to test some Web APIs on my local dev environment.

In addition, I've downloaded the Newman cmd-line utility for Postman.

jenkins整合postman 二

See https://www.getpostman.com/docs/newman_intro for more info.

So the Postman app is working fine, and the cmd-line utility is working too.

However, once I integrate it with my Jenkins test server, the tests are failing.

The main problem is that it's not able to launch Newman.

In a standard cmd prompt, I can successfully run the Newman test script as :

  newman -c API-Collection.json -n 3 

running n number of times.

And in the Jenkins build server GUI, I add the build script under the "Execute Shell" option.

But it doesn't find Newman, as this build error shows:

  FailedConsole Output

Started by user anonymous
Building in workspace C:Program Files (x86)JenkinsworkspaceWeb Api Test1 (Team Gecko)
[Web Api Test1 (Team Gecko)] $ "C:Program Filesinsh.exe" -xe C:WindowsTEMPhudson2522506155962538386.sh
+ newman -c C:UsersobertjmDocumentsPOSTMAN FilesWorkbench-API-Collection.json -n 3 -y 1000 --exitCode 1 -o output.json -H output.html
C:WindowsTEMPhudson2522506155962538386.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.

thanks, Bob

解决方案

Final solution was :

1) Add build step "Execute Windows batch command" and add two lines below:

2) change dir to newmanin:

  cd Usersobappdataoaming
pm
ode_modules
ewmanin

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"

The two tricky parts were:

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) Trying to locate the Newman module was difficult, as it's hidden inside %appdata% folder (i.e. c:usersob$appdata$ ).

I hope this helps someone in the future.

good luck.