DEV Community

Hassan BOLAJRAF
Hassan BOLAJRAF

Posted on

2

Azure DevOps | Running a Postman Collection using Newman Docker Image

Note
You can check other posts on my personal website: https://hbolajraf.net

Running a Postman Collection using Newman Docker Image

Newman is a command-line collection runner for Postman that allows you to automate and test your APIs. You can use the Newman Docker image to run Postman collections in a containerized environment.

Prerequisites

Before you begin, make sure you have Docker installed on your system.

Step 1: Pull the Newman Docker Image

Open your terminal and pull the Newman Docker image from Docker Hub using the following command:

docker pull postman/newman
Enter fullscreen mode Exit fullscreen mode

Step 2: Create a Postman Collection

Create a Postman collection that includes the API requests you want to run. You can use the Postman app to create and export collections.

Step 3: Export Your Postman Collection

Export your Postman collection as a JSON file. You can do this by opening the collection in Postman, clicking the "Export" button, and selecting "Collection v2" or "Collection v2.1" as the export format.

Step 4: Run the Postman Collection using Newman

Use the Newman Docker image to run your Postman collection as follows:

docker run -t postman/newman run <path-to-collection-file.json> --env-var VAR1=Value1 --env-var VAR2=Value2
Enter fullscreen mode Exit fullscreen mode
  • <path-to-collection-file.json>: Replace this with the path to the Postman collection JSON file you exported in step 3.

  • --env-var VAR1=Value1 and --env-var VAR2=Value2: If your collection relies on environment variables, you can set them using the --env-var flag.

Example

Here's an example command to run a Postman collection named "my-api-tests.json" with environment variables:

docker run -t postman/newman run my-api-tests.json --env-var API_URL=https://api.example.com --env-var API_KEY=your-api-key
Enter fullscreen mode Exit fullscreen mode

Additional Options

You can customize the Newman run using various Newman CLI options. For example, you can specify reporters, specify a folder for reports, and more.

What Next?

Using the Newman Docker image, you can easily automate the testing of your APIs by running Postman collections within a containerized environment. This is particularly useful for continuous integration and automated testing pipelines.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

If you found this post useful, please drop a ❤️ or leave a kind comment!

Okay