You can run Postman scripts from the command line with Newman, but if you want to run these scripts as part of your Continuous Integration environment, you can run it with Docker or directly on Jenkins. In case you prefer to use Docker, you can get started by downloading the Jenkins Docker instance and changing the Dockerfile to include node using the following node installation code found in the Docker/Jenkins Repository:
# Install Node RUN curl -sL https://deb.nodesource.com/setup_4.x | bash RUN apt-get -y install nodejs RUN node -v RUN npm -v RUN npm install -g newman
Then, you will need to rebuild the Docker image and start the container with the same instructions as in the Jenkins Docker Repository.
You should now have a fully working Jenkins instance installed locally. Great! Now back to the task at hand using the newly-installed instance of Jenkins:
- Create a new “Freestyle” job in Jenkins.
You will set it up to be able to upload the collection as a parameter. When you do this with your own projects, you should commit the Postman collection into whatever repository you’re using and pull directly from that repository to build by selecting “this project is parametrized” and then choosing “Add Parameter” with a “File Parameter.”
- Select two file uploads – one for the collection and one for the environment.
- Add a post-build step with “Execute Shell”. You’ll use the same command you used to run it from your own command line earlier (If you are using the same OS) except your path should be collection.js, as you named it ‘newman run collection.json’ in the File Parameter name field.
- Now test it and run the build. I just uploaded the collection.json since I’m not using the environment file yet, but you can add it to the command line with:
newman run collection.json –e environment.json
If you want to use the built in JUnit Jenkins viewer, you can archive the XML test result and point the tests to it. Below there is a sample of how you might archive and use the JUnit test results.
Resources: https://www.qasymphony.com/blog/automated-api-testing-tutorial/
Very helpful, thank you.
I think you’re missing ‘–reporter-junit-export newman.xml’ at the end of your build command?
Ah yes, I was talking about xml report and haven’t added to the jenkins job. Thank you ! I’m going to edit as soon as I have my computer