Skip to content

Instantly share code, notes, and snippets.

@arifsuhan
Last active October 31, 2021 18:39
Show Gist options
  • Save arifsuhan/56f5442c5de4a2146e78404a8ea5d757 to your computer and use it in GitHub Desktop.
Save arifsuhan/56f5442c5de4a2146e78404a8ea5d757 to your computer and use it in GitHub Desktop.
Run Postman collection with Jenkins and Newman Runner

Newman Runner Setup

  1. Install npm
  sudo apt install npm
  1. Install Newman Runner globally
  npm install -g newman
  1. Check postman scripts
  newman run [collection.json] -e [env.json]

Jenkins Setup

  1. Download Jenkins war file from here
  2. Run jenkins
  java -jar jenkins.war
  1. Go to Jenkins Portal: http://localhost:8080
  2. Create new Job
  3. Select Freestyle Project and click ok
  4. Add a build step and select bash shell command
  5. Paste it
  newman run [collection.json] -e [env.json] --suppress-exit-code 1
  1. Click Save
  2. Finally click Build Now option

Reference:

https://learning.postman.com/docs/running-collections/using-newman-cli/integration-with-jenkins/

Jenkins Runner Script

#!/bin/bash
java -jar jenkins.war

Docker Postman

  • CLI Command: sh [filename.sh] [collection.json] [env.json]
collection_Json=$1
env_Json=$2
report_name="Automate Postman Test Reporting"

# get docker image
docker pull postman/newmain

# create newman container instance, run postman collection and get test report
docker run -v ~/postman:/etc/newman --entrypoint /bin/sh -t postman/newman  -c "npm install -g newman-reporter-htmlextra;newman run $collection_Json -e $env_Json -r htmlextra --reporter-htmlextra-title '$report_name' "

# run server to see report
python -m http.server 8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment