$npx -y skills add LambdaTest/agent-skills --skill postman-to-newmanGenerate Newman CLI commands, configuration files, Jenkins pipeline scripts, and shell automation for running Postman collections in CI/CD or local environments. Use this skill whenever the user wants to run Postman collections from the command line, automate API tests, integrate
| 1 | # Postman Newman Automation |
| 2 | |
| 3 | Generates **Newman CLI** commands, **shell scripts**, and **Jenkins pipeline** configs |
| 4 | for running Postman collections in automated environments. |
| 5 | |
| 6 | --- |
| 7 | |
| 8 | ## Newman Basics |
| 9 | |
| 10 | Newman is Postman's CLI runner. Install with: |
| 11 | ```bash |
| 12 | npm install -g newman |
| 13 | # Optional HTML reporter: |
| 14 | npm install -g newman-reporter-htmlextra |
| 15 | ``` |
| 16 | |
| 17 | ### Core Command Structure |
| 18 | ```bash |
| 19 | newman run <collection> \ |
| 20 | --environment <env-file> \ |
| 21 | --globals <globals-file> \ |
| 22 | --iteration-count <n> \ |
| 23 | --iteration-data <csv-or-json> \ |
| 24 | --reporters <reporter-list> \ |
| 25 | --reporter-htmlextra-export <output.html> \ |
| 26 | --reporter-junit-export <results.xml> \ |
| 27 | --timeout-request <ms> \ |
| 28 | --delay-request <ms> \ |
| 29 | --bail \ |
| 30 | --color on |
| 31 | ``` |
| 32 | |
| 33 | --- |
| 34 | |
| 35 | ## Step 1 — Gather Requirements |
| 36 | |
| 37 | Ask or infer from context: |
| 38 | |
| 39 | | Parameter | Question | |
| 40 | |---|---| |
| 41 | | Collection source | File path, URL, or Postman API UID? | |
| 42 | | Environment | File path or inline variables? | |
| 43 | | Reporter(s) | CLI only, HTML report, JUnit XML? | |
| 44 | | Fail behavior | Stop on first failure (`--bail`) or run all? | |
| 45 | | Iterations | Single run or data-driven (CSV/JSON)? | |
| 46 | | Target | Local shell, Jenkins, or both? | |
| 47 | |
| 48 | --- |
| 49 | |
| 50 | ## Step 2 — Generate Newman Command |
| 51 | |
| 52 | ### Basic run (local) |
| 53 | ```bash |
| 54 | newman run collection.json \ |
| 55 | --environment environment.json \ |
| 56 | --reporters cli,htmlextra \ |
| 57 | --reporter-htmlextra-export reports/report.html \ |
| 58 | --bail |
| 59 | ``` |
| 60 | |
| 61 | ### Run from Postman API (by UID) |
| 62 | ```bash |
| 63 | newman run "https://api.getpostman.com/collections/<UID>?apikey={{POSTMAN_API_KEY}}" \ |
| 64 | --environment environment.json \ |
| 65 | --reporters cli,junit \ |
| 66 | --reporter-junit-export results/junit.xml |
| 67 | ``` |
| 68 | |
| 69 | ### Data-driven run (CSV) |
| 70 | ```bash |
| 71 | newman run collection.json \ |
| 72 | --iteration-data test-data.csv \ |
| 73 | --iteration-count 5 \ |
| 74 | --reporters cli,htmlextra \ |
| 75 | --reporter-htmlextra-export reports/data-driven-report.html |
| 76 | ``` |
| 77 | |
| 78 | ### With environment variable overrides (no file needed) |
| 79 | ```bash |
| 80 | newman run collection.json \ |
| 81 | --env-var "base_url=https://staging.api.example.com" \ |
| 82 | --env-var "token=abc123" \ |
| 83 | --reporters cli |
| 84 | ``` |
| 85 | |
| 86 | --- |
| 87 | |
| 88 | ## Step 3 — Shell Script |
| 89 | |
| 90 | Generate a reusable shell script: |
| 91 | |
| 92 | ```bash |
| 93 | #!/bin/bash |
| 94 | set -e |
| 95 | |
| 96 | # Configuration |
| 97 | COLLECTION="./collection.json" |
| 98 | ENVIRONMENT="./environment.json" |
| 99 | REPORT_DIR="./reports" |
| 100 | TIMESTAMP=$(date +"%Y%m%d_%H%M%S") |
| 101 | |
| 102 | # Ensure report directory exists |
| 103 | mkdir -p "$REPORT_DIR" |
| 104 | |
| 105 | echo "Running Newman collection: $COLLECTION" |
| 106 | |
| 107 | newman run "$COLLECTION" \ |
| 108 | --environment "$ENVIRONMENT" \ |
| 109 | --reporters cli,htmlextra,junit \ |
| 110 | --reporter-htmlextra-export "$REPORT_DIR/report_$TIMESTAMP.html" \ |
| 111 | --reporter-junit-export "$REPORT_DIR/junit_$TIMESTAMP.xml" \ |
| 112 | --timeout-request 10000 \ |
| 113 | --bail |
| 114 | |
| 115 | EXIT_CODE=$? |
| 116 | |
| 117 | if [ $EXIT_CODE -eq 0 ]; then |
| 118 | echo "✅ All tests passed." |
| 119 | else |
| 120 | echo "❌ Tests failed. Check report: $REPORT_DIR/report_$TIMESTAMP.html" |
| 121 | exit $EXIT_CODE |
| 122 | fi |
| 123 | ``` |
| 124 | |
| 125 | --- |
| 126 | |
| 127 | ## Step 4 — Jenkins Pipeline |
| 128 | |
| 129 | ### Declarative Jenkinsfile (preferred) |
| 130 | |
| 131 | ```groovy |
| 132 | pipeline { |
| 133 | agent any |
| 134 | |
| 135 | environment { |
| 136 | POSTMAN_ENV = credentials('postman-environment-file') // Jenkins credential ID |
| 137 | } |
| 138 | |
| 139 | stages { |
| 140 | stage('Install Newman') { |
| 141 | steps { |
| 142 | sh 'npm install -g newman newman-reporter-htmlextra' |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | stage('Run API Tests') { |
| 147 | steps { |
| 148 | sh """ |
| 149 | newman run collection.json \\ |
| 150 | --environment ${POSTMAN_ENV} \\ |
| 151 | --reporters cli,htmlextra,junit \\ |
| 152 | --reporter-htmlextra-export reports/report.html \\ |
| 153 | --reporter-junit-export reports/junit.xml \\ |
| 154 | --timeout-request 10000 \\ |
| 155 | --bail |
| 156 | """ |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | post { |
| 162 | always { |
| 163 | // Archive HTML report |
| 164 | publishHTML(target: [ |
| 165 | allowMissing: false, |
| 166 | alwaysLinkToLastBuild: true, |
| 167 | keepAll: true, |
| 168 | reportDir: 'reports', |
| 169 | reportFiles: 'report.html', |
| 170 | reportName: 'Newman API Test Report' |
| 171 | ]) |
| 172 | // Archive JUnit results |
| 173 | junit 'reports/junit.xml' |
| 174 | } |
| 175 | failure { |
| 176 | echo 'API tests failed! Check the Newman report.' |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | ``` |
| 181 | |
| 182 | ### Scripted Jenkinsfile (if declarative not available) |