Skip to content

GitLab CI template for Postman

This project implements a generic GitLab CI template for running Postman automated tests.

Usage

In order to include this template in your project, add the following to your gitlab-ci.yml:

include:
  - project: 'to-be-continuous/postman'
    ref: '2.0.1'
    file: '/templates/gitlab-ci-postman.yml'

# Pipeline steps
stages:
  - acceptance # required by Postman template
  # TODO: add all other required stages

postman job

This job starts Postman automated tests.

It uses the following variable:

Name description default value
POSTMAN_IMAGE The Docker image used to run Postman CLI. postman/newman:latest
POSTMAN_COLLECTIONS The matcher to select Postman collection file(s) to run. postman/*collection.json
POSTMAN_EXTRA_ARGS Newman extra run options (to use global variables, an environment or a data source for e.g.) none
REVIEW_ENABLED Set to true to enable Postman tests on review environments (dynamic environments instantiated on development branches) none (disabled)

Unit tests report integration

Postman test reports are integrated to GitLab by generating JUnit reports.

This is done using the newman JUnit reporter with the following CLI options: --reporters cli,junit --reporter-junit-export postman-junit.xml

Postman {{base_url}} auto evaluation

By default, the Postman template auto-evaluates a {{base_url}} variable (i.e. the variable pointing at server under test) by looking either for a $environment_url variable or for an environment_url.txt file.

Therefore if an upstream job in the pipeline deployed your code to a server and propagated the deployed server url, either through a dotenv variable $environment_url or through a basic environment_url.txt file, then the Postman test will automatically be run on this server.

⚠️ all our deployment templates implement this design. Therefore even purely dynamic environments (such as review environments) will automatically be propagated to your Postman tests.

Gitlab compatibility

ℹ️ This template is actually tested and validated on GitLab Community Edition instance version 13.12.11