TeamCity CI/CD with BrowserStack Load Testing
Integrate BrowserStack Load Testing into JetBrains TeamCity build configurations to run load tests in your self-hosted CI/CD workflows.
You can add BrowserStack Load Testing to your TeamCity build configurations so that every build triggers a load test. This integration works with self-hosted TeamCity Server installations.
Prerequisites
Make sure you have the following before you start:
- A BrowserStack account with access to Load Testing.
- A self-hosted TeamCity Server with at least one authorised build agent (local or remote, Linux preferred).
- TeamCity project parameters for your BrowserStack credentials. You can find the credentials on your account’s profile page:
-
BROWSERSTACK_USERNAME: Your BrowserStack username. -
BROWSERSTACK_ACCESS_KEY: Your BrowserStack access key.
-
To add the variables:
- Open your TeamCity project.
- In the project edit view, navigate to Parameters.
- Click Add new parameter:
- Name:
env.BROWSERSTACK_USERNAME, Type: Password, Value: your BrowserStack username. - Name:
env.BROWSERSTACK_ACCESS_KEY, Type: Password, Value: your BrowserStack access key.
- Name:
- Save.
The env. prefix tells TeamCity to expose these as environment variables to every script step. The Password type masks the value in build logs.
TeamCity build configuration
Use the following TeamCity Kotlin DSL to define the build configuration as code. Save it under .teamcity/settings.kts in your repository and enable Versioned Settings with format Kotlin in your project settings. Alternatively, replicate the same step structure manually via the TeamCity UI.
import jetbrains.buildServer.configs.kotlin.*
import jetbrains.buildServer.configs.kotlin.buildSteps.script
import jetbrains.buildServer.configs.kotlin.triggers.vcs
version = "2024.03"
project {
buildType(LoadTest)
params {
password("env.BROWSERSTACK_USERNAME", "credentialsJSON:browserstack-username")
password("env.BROWSERSTACK_ACCESS_KEY", "credentialsJSON:browserstack-access-key")
}
}
object LoadTest : BuildType({
name = "BrowserStack Load Test"
artifactRules = "reports-*/browserstack-load-test-report-*.xml"
vcs {
root(DslContext.settingsRoot)
}
steps {
script {
name = "Run unit tests"
scriptContent = """echo "Running unit tests""""
}
script {
name = "Download BrowserStack CLI"
scriptContent = """
OS=${'$'}(uname -s); ARCH=${'$'}(uname -m)
[ "${'$'}OS" = "Darwin" ] && OS=macos || OS=linux
case "${'$'}ARCH" in *arm*) ARCH=arm64 ;; *) ARCH=x64 ;; esac
curl -fL "https://load-api.browserstack.com/api/v1/binary?os=${'$'}{OS}&arch=${'$'}{ARCH}" -o browserstack-cli.zip
unzip -oq browserstack-cli.zip
chmod +x browserstack-cli
""".trimIndent()
}
script {
name = "Checkout sample Playwright project"
scriptContent = """
curl -L https://github.com/browserstack/browserstack-playwright-load-testing-sample/archive/refs/heads/CI/CD-Sample-Playwright.tar.gz \
| tar -xz --strip-components=1
""".trimIndent()
}
script {
name = "Run BrowserStack load test"
scriptContent = """./browserstack-cli load run"""
}
}
triggers {
vcs { }
}
features {
feature {
type = "JetBrains.SharedResources"
}
}
requirements {
contains("teamcity.agent.jvm.os.name", "Linux")
}
})
Result
When this build runs, it:
- Downloads the BrowserStack CLI for the current agent OS and architecture.
- Fetches the BrowserStack Playwright load-testing sample project.
- Starts a BrowserStack Load Testing run using your BrowserStack credentials, sourced from the project parameters.
- Publishes the generated JUnit XML reports as a build artifact.
Notes
- The
${'$'}Kotlin escape sequence inside thescriptContentblocks is required because Kotlin’s triple-quoted strings interpolate${...}syntax. Without the escape, Kotlin evaluates${OS}as a Kotlin expression at compile time and fails. The escape ensures the literal string${OS}reaches the shell at runtime. - The
requirements { contains("teamcity.agent.jvm.os.name", "Linux") }clause restricts the build to Linux agents. Remove or relax this for macOS and Windows agents. - For UI-driven build configuration (instead of versioned settings via Kotlin DSL), replicate the four script steps as Command Line build steps in the configuration UI.
- TeamCity Professional edition (free) supports up to 3 build agents and 100 build configurations.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!