How to run API tests in Jenkins
Plenty of teams still run their builds on Jenkins, and there's nothing wrong with that. Jenkins reads JUnit reports out of the box, keeps credentials in its own store, and runs anything you can run in a shell. That's all you need to run API tests with the Requestarium CLI.
Before you start
- Node.js 20.10 or later on the agent, or a Docker agent with a
node:22image. - An API token from Settings → API tokens in Requestarium. In Jenkins, add it under Manage Jenkins → Credentials as a Secret text credential with the ID
requestarium-token. Add any API keys your requests need the same way, for examplestaging-api-key.

The Jenkinsfile
Jenkinsfile
pipeline {
agent { docker { image 'node:22' } }
environment {
REQUESTARIUM_TOKEN = credentials('requestarium-token')
API_KEY = credentials('staging-api-key')
}
stages {
stage('Install CLI') {
steps {
sh 'npm install -g @requestarium/cli'
}
}
stage('API tests') {
steps {
sh '''
requestarium run-collection "Orders API" --env Staging --env-var API_KEY \
--junit results.xml --html report.html --save-run --no-color
'''
}
}
}
post {
always {
junit 'results.xml'
archiveArtifacts artifacts: 'report.html', allowEmptyArchive: true
}
}
}How it fits together:
credentials(...)exposes the secret as an environment variable and masks it in the console log. The CLI usesREQUESTARIUM_TOKENautomatically, so there's no login step.--env-var API_KEYmakes the Jenkins secret available to your requests as{{API_KEY}}, masked in reports too.junit 'results.xml'publishes the results. Each request run is a test suite and eachpm.testis a test case, so Jenkins' test trend graph shows API tests next to your unit tests.--no-colorkeeps the console log readable if you don't use the ANSI color plugin.--save-runrecords the run in Requestarium with the branch, commit and a link back to the Jenkins build.
Without Docker
If your agents run Node.js directly, drop the docker agent and use agent any. If you can't install packages globally, prefix the command with npx:
Jenkinsfile
sh 'npx @requestarium/cli run-collection "Orders API" --env Staging --junit results.xml'Behind a corporate proxy
Jenkins agents often sit behind a proxy and trust an internal certificate authority. The CLI has flags for both:
Terminal
requestarium run-collection "Orders API" --env Staging \
--proxy http://proxy.internal:3128 --ca-cert /etc/ssl/certs/company-ca.pemNightly regression
Add a trigger to run the pipeline every night, and fail it on slow responses as well as broken ones:
Jenkinsfile
triggers { cron('H 3 * * *') }Terminal
requestarium run-collection "Orders API" --env Staging --max-p95 800 --save-run