0
0
PostmanHow-ToBeginner ยท 4 min read

How to Use Newman with Jenkins in Postman for API Testing

To use Newman with Jenkins for Postman API tests, first install Newman on the Jenkins server, then create a Jenkins job that runs Newman commands to execute your Postman collections. This setup automates API testing by integrating Postman tests into Jenkins pipelines.
๐Ÿ“

Syntax

The basic syntax to run a Postman collection using Newman in Jenkins is:

  • newman run <collection-file>: Runs the Postman collection JSON file.
  • --environment <env-file>: (Optional) Specifies environment variables file.
  • --reporters <reporter-names>: Defines output report formats like CLI, HTML, JSON.
  • --reporter-<reporter-name>-export <file-path>: Exports the report to a file.

In Jenkins, you use this command inside a build step (e.g., Execute shell) to run tests automatically.

bash
newman run collection.json --environment environment.json --reporters cli,html --reporter-html-export report.html
๐Ÿ’ป

Example

This example shows how to configure a Jenkins freestyle job to run a Postman collection using Newman.

  1. Install Node.js and Newman on the Jenkins server.
  2. Create a Jenkins job and add an 'Execute shell' build step.
  3. Use the Newman command to run your collection and generate reports.
bash
# Install Newman globally (run once on Jenkins server)
npm install -g newman

# Jenkins build step command to run tests
newman run /path/to/collection.json --environment /path/to/environment.json --reporters cli,json --reporter-json-export /path/to/report.json
Output
newman โ†’ collection.json โ†’ environment.json โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ Newman 5.3.2 โ”‚ โ”‚ โ”‚ โ”‚ Run summary โ”‚ โ”‚ โœ“ 10 tests passed โ”‚ โ”‚ โœ— 0 tests failed โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โš ๏ธ

Common Pitfalls

Common mistakes when using Newman with Jenkins include:

  • Not installing Newman or Node.js on the Jenkins server, causing command not found errors.
  • Using incorrect file paths for collections or environment files.
  • Not setting executable permissions for scripts or Jenkins build steps.
  • Ignoring Jenkins workspace cleanup, leading to stale reports.
  • Not configuring Jenkins to archive or display test reports.

Always verify Newman installation and file paths before running Jenkins jobs.

bash
## Wrong: Missing Newman install
newman run collection.json

## Right: Install Newman first
npm install -g newman
newman run collection.json
๐Ÿ“Š

Quick Reference

Summary tips for using Newman with Jenkins:

  • Install Node.js and Newman globally on Jenkins server.
  • Use absolute paths for collection and environment files.
  • Run Newman commands in Jenkins build steps (shell or batch).
  • Use --reporters to generate readable test reports.
  • Archive reports in Jenkins for easy access.
โœ…

Key Takeaways

Install Newman and Node.js on the Jenkins server before running tests.
Use Jenkins build steps to run Newman commands with correct file paths.
Generate and archive test reports for visibility in Jenkins.
Verify environment and collection files exist and are accessible.
Avoid common errors by checking permissions and installation status.