Pipeline Parameters
Sometimes a pipeline needs user input – for example, which branch to build, or whether to deploy to production. Pipeline parameters allow you to make builds configurable.
Declaring Parameters
In Declarative Pipeline, use the
parameters directive inside pipeline. Common parameter types:- string: A text field.
- choice: A dropdown list.
- booleanParam: A checkbox.
- text: Multi‑line text.
- password: Hidden input.
pipeline {
agent any
parameters {
string(name: 'BRANCH', defaultValue: 'main', description: 'Git branch to build')
choice(name: 'ENVIRONMENT', choices: ['dev', 'staging', 'prod'], description: 'Deploy environment')
booleanParam(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests?')
}
stages {
stage('Build') {
steps {
echo "Building branch ${params.BRANCH}"
echo "Environment: ${params.ENVIRONMENT}"
}
}
}
}Using Parameters
Parameters are accessible via the
params object, e.g., params.BRANCH. They are also available as environment variables (with uppercase name), but using params is clearer.Parameterized Triggers
When you trigger a job remotely (e.g., from another pipeline), you can pass parameters using JSON or the
build step.Handling Missing Parameters
If a parameter is not set, you can provide a default or use
params.get('name', defaultValue). For boolean parameters, the default is often false.Scripted Pipeline Parameters
In Scripted Pipeline, parameters are defined using the
properties step:properties([
parameters([
string(name: 'BRANCH', defaultValue: 'main'),
choice(name: 'ENV', choices: ['dev','prod'])
])
])
node {
echo "Branch: ${params.BRANCH}"
}Two Minute Drill
- Parameters make pipelines configurable.
- Types:
string,choice,booleanParam,text,password. - Access via
params.NAME. - Set defaults to avoid user errors.
Need more clarification?
Drop us an email at career@quipoinfotech.com
