The Simplest Way to Make k6 and Teamcity Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

You pair k6 and TeamCity to run load tests inside your build pipeline. TeamCity starts the test run, and k6 sends traffic to your staging app. This workflow catches slow database queries and broken endpoints before code reaches users. Engineering teams get fast feedback on every pull request without manual test steps. How k6 and TeamCity share keys and test data TeamCity uses build agents to pull your code and start the test script. The build agent needs a secret key to talk to the test targ

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You pair k6 and TeamCity to run load tests inside your build pipeline. TeamCity starts the test run, and k6 sends traffic to your staging app.

This workflow catches slow database queries and broken endpoints before code reaches users. Engineering teams get fast feedback on every pull request without manual test steps.

How k6 and TeamCity share keys and test data

TeamCity uses build agents to pull your code and start the test script. The build agent needs a secret key to talk to the test target. Teams also store cloud keys when they send load test metrics out. TeamCity holds these keys in its secret store and passes them to the agent.

When the step starts, k6 reads those keys from the local agent memory. It then sends web requests to your test app at a set rate. As the test runs, k6 tracks response times, error rates, and total requests. When the run ends, k6 writes a summary file to the agent disk.

TeamCity reads that output file to check if the build passed or failed. If response times cross your limit, TeamCity marks the build step as failed. It also saves the raw output logs so engineers can review the charts. This data flow keeps load test results right next to unit test logs.

Common failure modes and how to scope roles

Many teams make the mistake of sharing one broad service account across projects. If every TeamCity agent uses the same static key, you lose clear audit trails. You cannot tell which pipeline or developer caused a spike in staging traffic. Worse, a leaked build log can expose a key that works everywhere.

Another common risk comes from test data that holds real user details. If a load test hits an endpoint that returns emails or card numbers, logs may catch them. When a request fails, the script often prints the full response body to the console. That means raw phone numbers or national IDs end up in build logs. Masking rewrites matched fields in results before the build log saves them.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix these gaps, give each TeamCity project its own narrow role. Set up your test targets to accept calls only from known agent IP ranges. Scope each key so it can only reach the staging app endpoints it tests. Rotate those keys on a regular schedule and clear agent memory after each run.

How to keep load test pipelines fast and clean

Load tests can slow down your build queue if you run them on every commit. Keep smoke tests small and fast for pull requests so developers do not wait. Run heavy stress tests on a nightly schedule using a separate pool of build agents. This split keeps your main build queue open for urgent code fixes.

You should also watch the health of the build agents during big runs. A heavy test can use up all CPU and memory on the agent machine. When the agent runs out of power, it reports false slowdowns in the test results. Size your agent machines to handle the traffic level your script tries to send.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

How does TeamCity know when a k6 test fails?

You set pass and fail rules inside your test script. When a metric crosses your limit, the tool exits with a non-zero status code. TeamCity sees that exit code and stops the build pipeline right away.

Where should we store API keys for k6 load tests?

Store all secret keys as password values inside the TeamCity project settings. Never commit keys or tokens inside your test script files in git. Pass them into the build agent only for the single step that needs them.

Can we run k6 tests on shared TeamCity build agents?

You can run small smoke tests on shared agents without trouble. For high-load tests, use dedicated build agents so you do not starve other jobs. Dedicated agents also give you steady CPU and network numbers for clean test scores.

The query runs. The emails stay hidden.