How to setup a Jenkins pipeline for postman tests
Node module newman can be used to execute Postman collections. Refer the following Package.json file. Here we are executing the postman collection inside the unit_tests folder using newman, also newman dependency is defined.
package.json
{ "name": "postman-newman-jenkins", "version": "1.0.0", "description": "My Test Project", "directories": { "tests": "tests" }, "scripts": { "newman-tests": "newman run unit_tests/my-collection.postman_collection.json --reporters cli,junit --reporter-junit-export newman.xml --insecure" }, "author": "Test Author", "dependencies": { "newman": "^3.5.2" }}
The following is the content of the Jenkinsfile. We are using NPM to install the dependencies and execute tests.
Jenkinsfile
pipeline { agent { label 'LinuxSlave' } stages { stage ('Checkout') { steps { checkout scm } } stage('Test'){ steps { sh 'npm install' sh 'npm run newman-tests' junit 'newman.xml' } } }}
you can avoid installing newman on the machine (slave/ master) and use docker
example pipeline script:
pipeline { agent any stages { stage('Test') { steps { sh 'docker run -t postman/newman_ubuntu1404 run https://www.getpostman.com/collections/8a0c9bc08f062d12dcda' } } }}
more info on docker & newman here