Integrate your Postman tests with Jenkins using Newman

Jenkins is an open source automation server that can act as a continuous integration (CI) server or a continuous delivery (CD) hub. You can integrate your Postman tests with Jenkins using Newman. This enables you to run a Postman Collection and its API tests directly from Jenkins. You can also specify the frequency that Jenkins runs a collection.

This guide uses a Jenkins installation that runs locally, but you'll typically run Jenkins on a build server in your production environment.

Developing an API? Postman offers built-in tools to integrate your API with some of the most widely-used continuous integration (CI) tools, including Jenkins. After you set up CI for your API, you can view the status of builds or kick off a new build, all from within Postman. You can also use Newman to run API tests as part of your CI pipeline. To learn more, see CI integrations.

Install Newman in Jenkins

Install Jenkins if you haven't already, and start it. By default, Jenkins is configured at http://localhost:8080 if you're running it locally. Install the NodeJS plugin in Jenkins, then install Newman in it.

To install NodeJS in Jenkins, do the following:

  1. Select Manage Jenkins.
  2. Under System Configuration, select Plugins.
  3. Select Available plugins, and search for "NodeJS".
  4. Select the checkbox next to NodeJS, and select Install.

To install Newman in Jenkins, do the following:

  1. Select Manage Jenkins.
  2. Under System Configuration, select Tools.
  3. Under NodeJS installations, select Add NodeJS.
  4. Enter a name for the NodeJS installation.
  5. In Global npm packages to install, enter newman.
  6. Select Save.

Configure Jenkins

After you install Newman in Jenkins, you can configure Jenkins to run a collection using Newman. You'll need a Postman Collection that has a few requests with tests. Then export the collection as a JSON file so you can run it using Newman.

Optionally, you can import a sample "Hello World" collection into your workspace to follow these instructions. Select the Run in Postman button to import the collection.

Run in Postman

To configure Jenkins to run Newman, do the following:

  1. On the Dashboard page, select + New Item to create a new job.

  2. Select Freestyle project from the options, name your project, and select OK.

  3. On the Configure page, select Build Environment, and select the checkbox next to Provide Node & npm bin/ folder to PATH. Select the NodeJS installation where you installed Newman.

  4. Select Build Steps, and select Add build step > Execute shell to execute a shell command. Enter a shell command to run the collection using Newman, such as the following:

    newman run ~/Desktop/jenkins_demo_postman_collection.json
    
  5. Select Save.

Test Newman in Jenkins

  1. On the Dashboard page, select the job you configured to run Newman.

  2. Select Build Now to manually run the build. After the build runs, review the Build History to determine whether the build succeeded:

    • If the build succeeded, Jenkins indicates this with a green checkmark.

    • If the build failed, Jenkins indicates this with a red cross mark.

  3. Select the build from the Build History, then select Console Output to review the results of the collection run.

  4. If the build failed, go to the collection in Postman to fix your tests. Then export the collection as a JSON file, and run the build again.

Specify build frequency

You can configure Jenkins to run Newman at a specified frequency. This enables you to regularly run and test collections from Jenkins.

In your production environment, you can set up notifications and customize Jenkins to align with your organization's goals.

To set the frequency that Jenkins runs Newman, do the following:

  1. On the Dashboard page, select the job you configured to run Newman.

  2. Select Configure.

  3. On the Configure page, select Build Triggers, then select the checkbox next to Build periodically.

  4. Enter the schedule you'd like the build to run using cron syntax. For example, the following syntax sets the build frequency to every 15 minutes: H/15 * * * *.

    Select the help icon next to Schedule to learn how to specify the build frequency.

  5. Select Save.

Last modified: 2024/05/24