Running Postman collection in a CI/CD server with Jenkins and CLI tools (Newman, Postman CLI)

Ceren Çakır
5 min readFeb 24, 2024

--

  • Run with Postman Runner, Newman, Postman CLI, and Jenkins

If we have a Postman collection and we don’t want to run this collection manually for each test, we can run this collection in CI/CD server by using CLI tools such as Postman CLI and Newman, also we can run the collection with Jenkins.

I have a collection based on Trello. Click three dot and select “Run collection” option, then Runner screen is opened. Select “run manually” option at first. And click “Run Trello API” button

Click three dot and select “Edit” option. Then select “Runs” from the titles. This run is shown as “Ran locally using Collection Runner” in the Runs part. Its source should be shown as Runner.

We can get more details about requests and tests after running when you click on it. Details are shown below

After clicking the “View Summary”, we can see the results as a summary below.

  • There is an ID under the Collection details. This ID is used while running via Postman CLI.

And now, we are selecting “Automate runs via CLI” option. We need to configure CLI command to run on our build pipeline after downloading Postman CLI.

Then copy this command and run it in your local terminal. Before doing that, we need an API key, you can generate your own API key or if you have already an API key, you can use it. Then insert this key to the command.

I have already the API keys as you see below, then I inserted this key into the command. You can create your own API keys for each CLI tool. I have created different API keys for Postman CLI, Newman and Jenkins.

Then paste this command and run it in your local terminal. And then the collection starts to run.

At the end of the terminal, you can view the executed results.

Also, we can view the results under the Runs part.

  • Let’s keep going with Newman

To run Newman, ensure you have Node.js. The easiest way to Install Newman is using npm(node package manager)

Check here to install Node.js

Check here to install Newman

To check the versions, use the below command.

Newman is much more advanced compared to Postman CLI. As I said before, I already have the API key for Newman.

So now, click three dot and select “Share” option.

Click “Via API” tab in the opened “Share Trello API” screen. Then copy and paste the command to your terminal. access_key is the collection access key. It is displayed at the bottom of the API keys screen which I added a little above.

Then the collection starts to run.

ü,üthen the collection starts to run.

At the end of the terminal, you can view the executed results.

  • Let’s pass to the Jenkins

I run Jenkins with Docker. To install Docker Desktop, use this link. After installing Docker, run the necessary commands from a terminal window to run Jenkins. To learn more you may read this article. I do not detailed information about Docker, here I just want to show simple steps to run Jenkins with Docker. I’m only expressing what I’ve learned during this process

After Jenkins is opened and you logged in, click “new item”

Then write the item name and select freestyle project and click OK button

Select “run Shell” under the “Build steps” part.

Then build it and it starts running.

You can see the results in the console output.

You can view the results under the Runs part.

It’s displayed as “Ran in Jenkins build 11 using Newman” and the build count is shown there too.

If we have done anything wrong, we can see this as an error as below. For example, I’ve forgotten console.clear in prerequest-script parts and these are displayed as TypeError in the Console Output.

As a summary, if we have a Postman collection and we don’t want to run this collection manually for each test, we can run this collection in CI/CD server by using CLI tools such as Postman CLI and Newman, also we can run the collection with Jenkins.

I hope this article will be a little bit useful for anyone who needs it.

Write about what you learn. It pushes you to understand topics better. Sometimes the gaps in our knowledge only become clear when explaining things to others.

Thanks! :)

--

--

Ceren Çakır
Ceren Çakır

No responses yet