Add API tests to GitLab CI with one include

Running API tests in GitLab CI by hand takes a job, an image, a script and a JUnit report block. The requestarium-run template packs all of that into one file you include with a few inputs.

Set it up

  1. Copy the template into your repository as ci/requestarium-run.yml.
  2. In GitLab, open Settings → CI/CD → Variables and add REQUESTARIUM_TOKEN with an API token. Mark it Masked, and Protected if only protected branches should use it.
  3. Include it:
.gitlab-ci.yml
include:
  - local: ci/requestarium-run.yml
    inputs:
      suite: Smoke
      environment: Staging

That's the whole pipeline change. The job is called requestarium-run and runs in the test stage.

Inputs

InputDefaultWhat it does
collection, folderRun a collection, or one folder of it
suiteRun a test suite instead
environment, workspaceWhich environment and workspace
variablesKEY=VALUE pairs separated by spaces
save-runtrueSave the run to the history
bailfalseStop at the first failure
extra-argsMore CLI flags, like --retries 1
token-variableREQUESTARIUM_TOKENName of the CI/CD variable with the token
api-urlA self-hosted server
cli-versionlatest@requestarium/cli version
job-name, stagerequestarium-run, testJob name and stage
imagenode:22-alpineImage the job runs in

Set either collection or suite. With neither, or both, the job stops with a message saying so.

Two jobs from one template

Include the file twice with different job-names, for example a quick smoke suite on every merge request and a full regression after merge:

YAML
include:
  - local: ci/requestarium-run.yml
    inputs:
      job-name: api-smoke
      suite: Smoke
      environment: Staging
  - local: ci/requestarium-run.yml
    inputs:
      job-name: api-regression
      stage: post-merge
      collection: Users API
      folder: Regression
      environment: Staging
      cli-version: 0.7.0

stages: [test, post-merge]

api-regression:
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

The last block narrows when the included job runs, the normal GitLab way of extending an included job.

Review apps

A review app gets a new URL per merge request. Pass it through variables:

YAML
    inputs:
      suite: Smoke
      environment: Staging
      variables: "baseUrl=$REVIEW_APP_URL"

Make sure the job runs after the deploy job, with needs: on api-smoke pointing at your deploy job.

Separate tokens per project or group

With an organization token on the Team plan, each GitLab project can get its own token, revoked without touching the others. To name the variable differently, for example per environment:

YAML
    inputs:
      token-variable: REQUESTARIUM_TOKEN_PROD

See organization API tokens for CI.

What you get

  • The job log with each request's status and tests.
  • requestarium-results.xml as a JUnit report: failed tests show on the pipeline's Tests tab and in the merge request widget.
  • requestarium-report.json as an artifact, for scripts.
  • With save-run, the run in Requestarium's history with branch, commit and a link to the pipeline.