14 Newman Integration
title: "Newman Integration for CI/CD" description: "Integrate Postman collections with CI/CD pipelines using Newman. Learn CLI options, reporters, data-driven execution, environment injection, and integration with GitHub Actions, Jenkins, and GitLab CI." weight: 14 date: 2026-06-28 lastmod: 2026-06-28 tags: [api-development, postman] }
Newman executes Postman collections from the command line, enabling CI/CD integration. It supports reporters for CLI, HTML, JUnit, and JSON output. Newman accepts environment files, data files, and CLI options for flexible automation.
What You'll Learn
- Newman CLI options and configuration
- Reporter setup (CLI, HTML, JUnit, JSON)
- Environment variable injection
- CI/CD integration patterns
- Secret management
Why It Matters
Newman brings Postman collections into automated pipelines. Teams run the same collections they develop in Postman, ensuring consistency between manual and automated testing.
Real-World Use
Postman's own monitoring service uses Newman under the hood. GitHub Actions marketplace has Newman actions. Jenkins plugins support Newman integration for API test stages.
flowchart LR
CI[CI/CD Pipeline] --> Newman[Newman CLI]
Newman --> Collection[Collection JSON]
Newman --> Environment[Environment JSON]
Newman --> Data[Data File]
Newman --> Reporters[Reporters]
Reporters --> CLI[CLI Output]
Reporters --> HTML[HTML Report]
Reporters --> JUnit[JUnit XML]
Reporters --> JSON[JSON Results]
Newman --> ExitCode[Exit Code]
ExitCode --> PassOrFail[Pipeline Pass/Fail]
Teacher Mindset
Export collections and environments as version-controlled JSON files. Use Newman in CI with the same configuration as local runs. Inject secrets via environment variables. Generate JUnit reports for test visualization.
Code Examples
# Example 1: Newman basic CI integration
npm install -g newman
# Run with environment and data file
newman run api-tests.postman_collection.json \
--environment staging.postman_environment.json \
--folder "Users" \
--reporters cli,junit,htmlextra \
--reporter-junit-export results/junit-report.xml \
--reporter-htmlextra-export results/html-report.html \
--timeout-request 10000
# Check exit code
echo "Exit code: $?"
# Example 2: GitHub Actions workflow
name: Postman API Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
api-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Newman
run: npm install -g newman newman-reporter-htmlextra
- name: Run API Tests
run: |
newman run collections/api-tests.json \
--environment environments/ci.json \
--env-var "api_key=${{ secrets.API_KEY }}" \
--env-var "base_url=${{ vars.BASE_URL }}" \
--reporters cli,junit,htmlextra \
--reporter-junit-export results/junit.xml \
--reporter-htmlextra-export results/report.html
- name: Publish Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Postman API Tests
path: results/junit.xml
reporter: java-junit
- name: Upload HTML Report
uses: actions/upload-artifact@v3
if: always()
with:
name: api-test-report
path: results/report.html
// Example 3: Jenkins pipeline stage
stage('API Tests') {
agent {
docker {
image 'node:18'
}
}
steps {
sh '''
npm install -g newman newman-reporter-htmlextra
newman run collections/api-tests.json \
--environment environments/jenkins.json \
--env-var "api_key=${API_KEY}" \
--reporters cli,junit,htmlextra \
--reporter-junit-export results/junit.xml \
--reporter-htmlextra-export results/report.html
'''
}
post {
always {
junit 'results/junit.xml'
publishHTML(target: [
reportName: 'API Test Report',
reportDir: 'results',
reportFiles: 'report.html'
])
}
}
}
Common Mistakes
- Hardcoding API keys in environment files committed to version control
- Not installing Newman reporters before using them
- Forgetting to check the exit code in CI (non-zero = failure)
- Using different collection versions locally vs CI
- Not handling Newman timeout errors for slow APIs
Practice
- Install Newman and run a collection with CLI reporter.
- Run the same collection with HTML reporter and view the report.
- Add Newman to a GitHub Actions workflow.
- Inject environment variables from CI secrets.
- Challenge: Create a Jenkins pipeline that runs Newman tests, publishes JUnit results, and archives HTML reports.
FAQ
Mini Project
Set up a GitHub Actions pipeline for a Postman collection. The pipeline should: checkout the repository, install Newman with htmlextra reporter, run the collection with environment variables from GitHub secrets, generate JUnit and HTML reports, publish the JUnit report using test-reporter action, and archive the HTML report.
What's Next
Next, you will build a complete Postman project integrating all concepts.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro