bob.mazzo
bob.mazzo

Reputation: 5627

Integrate Postman test scripts with Jenkins build server

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.

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.

from cmd prompt

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

enter image description here

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.

thanks, Bob

Upvotes: 7

Views: 10521

Answers (3)

ashish bansal
ashish bansal

Reputation: 311

Integrate Postman with Jenkins on Windows Machine

Step #1 : Download Jenkins on your local windows machine .

URL to Download Jenkins :-- https://jenkins.io/download/ After successful download enter :- http://localhost:8080 Step #2 : Enter the name of the project and click on Freestyle project and save . screen 1

Step #3 : PostmanScriptTest2 job gets created and under source code management >build > click on execute windows batch command. screen 2

Step #3: Type in command under Execute Windows batch Command

C:\Users\ashish\AppData\Roaming\npm\newman run https://www.getpostman.com/collections/d231549a4assc77abcdbaf9c674

Click on save and apply. screen3

Step #4: Go to Jenkins Home Page and click on Manage Jenkins

screen4 Step #5 : Under manage Jenkins click on configure System .

screen5

Step #6 : Under Global Properties > check on environmental variables and enter

Name - PATH

Value - C:\Program Files\Nodejs screen 6

Step #7 : Under Shell , shell executable type in C:\Windows\System32\cmd.exe and click on save and apply .

screen7

Upvotes: 2

tiwari.vikash
tiwari.vikash

Reputation: 377

Run command "which newman" in command prommpt. It will return something like - /c/Users/user1/AppData/Roaming/npm/newman

Now use fully qualified path returned by above mentioned command in Jenkins windows batch command box -

c:/Users/user1/AppData/Roaming/npm/newman -c demo.postman_collection.json

Upvotes: 2

bob.mazzo
bob.mazzo

Reputation: 5627

Final solution was :

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

2) change dir to newman\bin:

  cd \Users\bob\appdata\roaming\npm\node_modules\newman\bin

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:\users\bob\$appdata$ ).

I hope this helps someone in the future.

good luck.

Upvotes: 9

Related Questions