Skip to content

An example of running Postman Collections with Newman via different CI systems.

Notifications You must be signed in to change notification settings

DannyDainton/postman-ci-pipeline-example

Repository files navigation

postman-ci-pipeline-example

This is very simple project to demonstrate using Newman to run a Postman collections through some of the different CI systems. There are a number of different ways that you can use Newman in these CI systems.

  • TravisCI is creating a node environment and installing the Newman NPM package, then running the Collection via a CLI script.
  • CircleCI is using the postman/newman orb, from there orb registry. This a packaged version of the Newman Docker image held on their internal registry.
  • Bitbucket Pipelines is creating an environment and using the postman/newman Docker image and running the collection file in a container.
  • GitLab is using the postman/newman Docker image and running the collection file in a container.

The collection and environment files have been taken from the All-Things-Postman Repo. Each of the different systems will output the same CLI summary to the console.

Build badges

Using Shields.io we can get a visual indication about about build status and display this on our repo. I've included the ones for Travis and CircleCI here as these run when a commit is made against this repo. I've added the ones for BitBucket and Gitlab to the sample projects on those repos.


TravisCI

Build Status

In order to use TravisCI in your own projects, you will need to signup and then sync it to your Github account. On the free TravisCI tier, you will only be able to run your Public repos through TravisCI.

More information about the sign up and set up process for TravisCI can be found here.

How does it work with TravisCI

All the magic happens in the .travis.yml file. This is building out the node environment and installing the required Newman module needed to run the collection file.

Once the node environment has been created, the script section is run - This would be run in the same way that you would run Newman from the command line on your local machine.

You can specify a number of different command line args to the script that would change the way that Newman runs the command. I've added the --color and --disable-unicode flags as an example of the args that can be used. More details about the other command line args can be found here.

language: node_js
node_js:
  - "14"

install:
  - npm install newman

before_script:
  - node --version
  - npm --version
  - node_modules/.bin/newman --version

script:
  - node_modules/.bin/newman run tests/Restful_Booker_Collection.postman_collection.json -e tests/Restful_Booker_Environment.postman_environment.json --color auto --disable-unicode

Once the collection has run via TravisCI, you will see the log output of that build in the Travis UI. Any Tests that are in the collection, will run and the results will be displayed in the log output.

An example of the summary run output...

TravisCI


CircleCI

Build Status

In order to use CircleCI on your projects you will need an account. You can sign in via Github, which makes it easier to add your projects from your repos.

More information about getting started with CircleCI, can be found here.

How does it work with CircleCI

All the magic happens in the .circleci/config.yml file. This is using the Postman Orb to run the collection file.

Orbs are packages of config that you can use to quickly get started with the CircleCI platform. Orbs enable you to share, standardize, and simplify config across your projects. You may also want to use orbs as a reference for config best practices. Refer to the CircleCI Orbs Registry for the complete list of available orbs.

The basic config.yml file will look like the example below. There several other Newman specific options available, just like when running Newman from the CLI. More information about the options can be found here.

version: 2.1
orbs:
  newman: postman/newman@0.0.2
jobs:
  build:
    executor: newman/postman-newman-docker
    steps:
      - checkout
      - newman/newman-run:
          collection: ./tests/Restful_Booker_Collection.postman_collection.json
          environment: ./tests/Restful_Booker_Environment.postman_environment.json

An example of the summary run output...

CircleCI


There a couple of other CI systems that I wanted to demo - These unlike TravisCI and CircleCI, hold the code in their own repos and not within Github. They both work in a simialir ways and use a .yml for the build config but the output can be seen in the application UI, rather than moving away to view this in a 3rd dashboard.

In order to use these CI systems you would need to create an account and sign in, before you're able to create your first projects.

Bitbucket Pipelines

How does it work with Bitbucket Pipelines

All the magic happens in the bitbucket.pipelines.yml file. This is using the postman/newman Docker image, to run the collection file.

image: postman/newman

pipelines:
  default:
    - step:
        script:
        - newman --version
        - newman run ./tests/Restful_Booker_Collection.postman_collection.json -e ./tests/Restful_Booker_Environment.postman_environment.json

An example of the summary run output...

Bitbucket Pipeline

A sample Bitbucket Pipeline project can be found here: https://bitbucket.org/ddainton/postman-ci-pipeline-example/src/master/


GitLab

How does it work with GitLab

All the magic happens in the .gitlab-ci.yml file. This is using the postman/newman Docker image, to run the collection file.

stages:
    - test

newman_tests:
    stage: test
    image:
        name: postman/newman
        entrypoint: [""]
    script:
        - newman --version
        - newman run ./Restful_Booker_Collection.postman_collection.json -e ./Restful_Booker_Environment.postman_environment.json

An example of the summary run output...

GitLab

A sample Gitlab project can be found here: https://gitlab.com/DannyDainton/postman-ci-pipeline-example


That's it - It's a very simple example of how you could use some of the CI Systems out there to run Postman collections with Newman.

If you have any questions, you can drop me a message on Twitter @dannydainton.

About

An example of running Postman Collections with Newman via different CI systems.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published