Right now your job is hardcoded. It always runs Chrome, always hits localhost, always runs the full suite. But what if QA lead says "Run smoke tests on Firefox against staging"? Do you create a separate job for every combination? No. You use parameterized builds.
Think of it like ordering chai. You do not have separate counters for "chai with sugar" and "chai without sugar." You have one counter and you tell them your preference. Parameters work the same way — one job, you choose the options at build time.
pipeline {
agent any
parameters {
choice(
name: 'BROWSER',
choices: ['chrome', 'firefox', 'edge'],
description: 'Browser to run tests'
)
choice(
name: 'ENVIRONMENT',
choices: ['local', 'staging', 'production'],
description: 'Target environment'
)
choice(
name: 'SUITE',
choices: ['testng-smoke.xml', 'testng-regression.xml', 'testng.xml'],
description: 'Test suite to run'
)
booleanParam(
name: 'HEADLESS',
defaultValue: true,
description: 'Run browser in headless mode'
)
}
stages {
stage('Run Tests') {
steps {
sh """
mvn clean test \
-DsuiteXmlFile=${params.SUITE} \
-Dbrowser=${params.BROWSER} \
-Dbase.url=${getBaseUrl(params.ENVIRONMENT)} \
-Dheadless=${params.HEADLESS}
"""
}
}
}
}
def getBaseUrl(env) {
switch (env) {
case 'staging': return 'https://staging.example.com'
case 'production': return 'https://www.example.com'
default: return 'https://www.testerrank.com'
}
}When you click "Build with Parameters," Jenkins shows a form with dropdowns for browser, environment, suite, and a checkbox for headless. Anyone on the team can run tests with custom settings. No code changes needed.
First time you run a parameterized pipeline, Jenkins shows "Build Now" instead of "Build with Parameters." This is normal — Jenkins needs to run the pipeline once to discover the parameters. After the first run, "Build with Parameters" appears.
Q: How do you handle running tests on different browsers and environments in CI?
A: I use parameterized builds in Jenkins. The Jenkinsfile defines choice parameters for browser (chrome, firefox, edge), environment (local, staging, production), and test suite (smoke, regression, full). A helper function maps environment names to base URLs. These parameters flow as Maven -D flags, which my BaseTest reads via System.getProperty(). So one pipeline handles all combinations — the tester just selects options from a dropdown when triggering the build. For nightly regression, the defaults run automatically.
Key Point: Parameterized builds let you choose browser, environment, and suite at build time. One job, many configurations.