Verify your thresholds are CI-ready
Before you connect k6 to a pipeline, confirm that your thresholds behave as gates. A threshold that passes means the deploy is acceptable. A threshold that fails means k6 returns a non-zero exit code, which the pipeline interprets as a failure. If your thresholds are too loose, every deploy passes regardless of performance. If you have no thresholds at all, k6 always exits with code 0 and the gate is meaningless.
To verify your thresholds are CI-ready, complete the following steps:
Open your k6 test script in your code editor and check the
thresholdssection in theoptionsblock. You should have at least one threshold defined. For example:export const options = { thresholds: { http_req_duration: ['p(95)<500'], http_req_failed: ['rate<0.01'], }, };If your script doesn’t have thresholds, add them now. At minimum, include a latency threshold (
http_req_duration) and an error rate threshold (http_req_failed).Run your test and confirm it passes with exit code
0:k6 run test.js echo $?The output of
echo $?should be0, meaning all thresholds passed. If the thresholds failed, adjust either your thresholds or your test target so you have a known-passing state.Temporarily tighten a threshold to force a failure. For example, change the latency threshold to an impossibly low value:
thresholds: { http_req_duration: ['p(95)<1'], http_req_failed: ['rate<0.01'], },Run the test again and confirm it fails with a non-zero exit code:
k6 run test.js echo $?The exit code should be non-zero (for threshold failures, k6 commonly returns
99). k6 prints which thresholds were breached in the end-of-test summary. This is the signal your pipeline uses to block a deploy.Revert the threshold to its original value so the test passes again.
Tip: Good CI thresholds are based on your actual performance baseline, not arbitrary numbers. If you’ve established a performance baseline, use the p95 latency and error rate from your baseline runs as starting points. To learn more, refer to Establish a performance baseline with k6 and Load test types.
In the next milestone, you parameterize your script so it can run against any environment without code changes.