k6 run: Usage, Options & Common CI Errors
k6 run drives a JavaScript load test and gates CI on its thresholds.
k6 is the modern load-testing tool for pipelines. Its killer CI feature is thresholds: when a threshold (e.g. p95 latency or error rate) is breached, k6 exits 99 and fails the job.
What it does
k6 run executes a JavaScript test script, ramping virtual users (VUs) to generate load and recording metrics like http_req_duration and http_req_failed. Thresholds defined in the script turn those metrics into a pass/fail gate for CI.
Common usage
k6 run script.js
k6 run --vus 50 --duration 30s script.js
k6 run -e BASE_URL=https://staging.example.com script.js
k6 run --out json=result.json script.js
k6 run --quiet --no-color script.js # CI-friendly outputOptions
| Flag | What it does |
|---|---|
| --vus <N> | Number of concurrent virtual users |
| --duration <t> | How long to run (e.g. 30s, 5m) |
| -e KEY=VALUE | Pass an environment variable to the script |
| --out <format> | Stream results (json=, influxdb=, csv=) |
| --no-thresholds | Run but do not fail on threshold breaches |
| -i / --iterations <N> | Run a fixed number of iterations total |
Common errors in CI
The defining CI behavior: when a threshold is crossed, k6 prints "some thresholds have failed" and exits with code 99 - that is the intended gate, not a bug. Exit 107 = a script/runtime error (e.g. a JS exception or a bad URL). "level=error ... dial: connection refused" means the target is not up yet (start the service or add a wait). Thresholds only fail the build if you do NOT pass --no-thresholds; keep them on in CI and pass --no-thresholds only for exploratory runs.