In this tutorial, you’ll learn how to build a single, parameterized Jenkins pipeline that can switch between branches, customize ports, and adjust timeouts—all without duplicating your Jenkinsfile. Parameterized pipelines make your CI/CD workflows more flexible and maintainable.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
What Is a Parameterized Pipeline?
A parameterized build in Jenkins lets you define input variables that users can set at build time. This approach helps you:- Reuse the same pipeline for multiple branches or environments
- Pass dynamic values such as branch names, ports, or timeouts
- Reduce Jenkinsfile duplication and improve maintainability
Example Repository
We’ll use the parameterized-pipeline-job-init GitHub repository, which contains a simple Spring Boot “Hello World” application. There are two branches:- main: Production pipeline with containerization and Kubernetes deployment
- test: Basic pipeline that builds, tests, and deploys locally

Pipeline Definition: test Branch
Pipeline Definition: main Branch
Goal: One Job for Both Branches
Instead of creating separate Jenkins jobs, we’ll parameterize a single pipeline so it can target either branch at build time.1. Create the Parameterized Job
- In Jenkins Classic UI, click New Item.
- Enter Parameterized Pipeline Job, select Pipeline, then click OK.
- Under Pipeline, choose Pipeline script from SCM.
- Point SCM to your Git repo and set Branch Specifier to
testfor now. - Keep Script Path as
Jenkinsfile.


2. Verify the test Branch
Run the job once to ensure the test pipeline works as expected. In Blue Ocean, you should see all stages complete successfully:

3. Define Build Parameters
Go back to Configure and enable This project is parameterized. Add the following parameters:| Parameter | Type | Default | Description |
|---|---|---|---|
| BRANCH_NAME | String | main | Git branch to build |
| APP_PORT | String | 6767 | Port for local or integration test |
| SLEEP_TIME | Choice | 10s | Delay before running tests |
You can add more parameters (e.g.,
TIMEOUT, ENVIRONMENT) to adapt this pipeline for different use cases.



Make sure to commit these parameterized Jenkinsfile changes to each branch; otherwise,
${params.*} will not be available.4. Update the test Branch Jenkinsfile
Switch to the test branch and edit Jenkinsfile to leverage the new parameters:
- BRANCH_NAME: test
- APP_PORT: 6767
- SLEEP_TIME: 5s

5. Update the main Branch Jenkinsfile
Repeat a similar update in the main branch to reference ${params.SLEEP_TIME}:
- BRANCH_NAME: main
- SLEEP_TIME: 15s

main branch pipeline honor the parameters:

Conclusion
By defining job-level parameters and referencing them in your Jenkinsfile, you can maintain a single pipeline that adapts to multiple branches and environments. This strategy:- Reduces duplication across branches
- Simplifies CI/CD maintenance
- Enables dynamic, user-driven builds