Discover how a simple parameters block can save you hours of repetitive work and mistakes!
Why Parameters block declaration in Jenkins? - Purpose & Use Cases
Imagine you need to run the same Jenkins job but with different inputs each time, like different server names or versions. Without parameters, you must edit the job every time or create many copies.
Manually changing job settings or duplicating jobs is slow and risky. You might forget to update something or make mistakes, causing failed builds or wasted time.
The parameters block lets you define inputs once. When you run the job, Jenkins asks for values. This makes the job flexible, reusable, and error-free without changing the code every time.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building version 1.0 on server A'
}
}
}
}pipeline {
agent any
parameters {
string(name: 'VERSION', defaultValue: '1.0', description: 'App version')
string(name: 'SERVER', defaultValue: 'A', description: 'Target server')
}
stages {
stage('Build') {
steps {
echo "Building version ${params.VERSION} on server ${params.SERVER}"
}
}
}
}You can run one Jenkins job many ways by just entering different inputs, saving time and avoiding errors.
A developer triggers a deployment job and enters the target environment and version number each time, without changing the pipeline code.
Manual job edits are slow and error-prone.
Parameters block lets you define inputs once for flexible runs.
This makes Jenkins jobs reusable and safer.