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
- Copy the template into your repository as
ci/requestarium-run.yml. - In GitLab, open Settings → CI/CD → Variables and add
REQUESTARIUM_TOKENwith an API token. Mark it Masked, and Protected if only protected branches should use it. - Include it:
include:
- local: ci/requestarium-run.yml
inputs:
suite: Smoke
environment: StagingThat's the whole pipeline change. The job is called requestarium-run and runs in the test stage.
Inputs
| Input | Default | What it does |
|---|---|---|
collection, folder | Run a collection, or one folder of it | |
suite | Run a test suite instead | |
environment, workspace | Which environment and workspace | |
variables | KEY=VALUE pairs separated by spaces | |
save-run | true | Save the run to the history |
bail | false | Stop at the first failure |
extra-args | More CLI flags, like --retries 1 | |
token-variable | REQUESTARIUM_TOKEN | Name of the CI/CD variable with the token |
api-url | A self-hosted server | |
cli-version | latest | @requestarium/cli version |
job-name, stage | requestarium-run, test | Job name and stage |
image | node:22-alpine | Image 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:
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_BRANCHThe 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:
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:
inputs:
token-variable: REQUESTARIUM_TOKEN_PRODSee organization API tokens for CI.
What you get
- The job log with each request's status and tests.
requestarium-results.xmlas a JUnit report: failed tests show on the pipeline's Tests tab and in the merge request widget.requestarium-report.jsonas an artifact, for scripts.- With
save-run, the run in Requestarium's history with branch, commit and a link to the pipeline.