What if you could run the same job many ways without rewriting a single line?
Why String, boolean, and choice parameters in Jenkins? - Purpose & Use Cases
Imagine you need to run a Jenkins job that asks your team for input like a name, a yes/no decision, or a choice from a list. Without parameters, you have to edit the job script every time to change these values.
Manually changing scripts is slow and risky. You might mistype values or forget to update something. It's like rewriting a letter every time you want to send it to a different friend instead of just filling in a form.
Using string, boolean, and choice parameters lets Jenkins ask for inputs before running a job. This makes your jobs flexible and safe. You just fill in the answers, and Jenkins uses them automatically.
def name = 'Alice' def deploy = false def env = 'dev' // Change these values in the script every time
parameters {
string(name: 'name', defaultValue: '', description: 'Enter your name')
booleanParam(name: 'deploy', defaultValue: false, description: 'Deploy now?')
choice(name: 'env', choices: ['dev', 'test', 'prod'], description: 'Select environment')
}You can run the same Jenkins job many ways without changing code, making automation easy and error-free.
A developer triggers a build and selects 'prod' environment and 'true' for deploy, all through a simple form, without touching the job script.
Manual input changes are slow and risky.
Parameters let Jenkins ask for inputs before running.
This makes jobs flexible, safe, and easy to reuse.
Practice
Solution
Step 1: Understand parameter types
String parameters allow users to input any text value.Step 2: Match requirement to parameter
Since the question asks for text input, String parameter fits best.Final Answer:
String parameter -> Option AQuick Check:
Text input = String parameter [OK]
- Choosing Boolean parameter for text input
- Confusing Choice parameter with String parameter
- Selecting File parameter which is for files
Solution
Step 1: Recall Jenkins Boolean parameter syntax
The correct syntax uses booleanParam with name, defaultValue, and description keys.Step 2: Compare options
booleanParam(name: 'DEPLOY', defaultValue: true, description: 'Deploy to production?') matches the correct syntax exactly; others have wrong names or keys.Final Answer:
booleanParam(name: 'DEPLOY', defaultValue: true, description: 'Deploy to production?') -> Option CQuick Check:
Boolean parameter syntax = booleanParam(name: 'DEPLOY', defaultValue: true, description: 'Deploy to production?') [OK]
- Using stringParam for boolean values
- Incorrect parameter function names like boolParam
- Passing boolean as string instead of boolean type
parameters {
choice(name: 'ENV', choices: ['dev', 'test', 'prod'], description: 'Select environment')
booleanParam(name: 'DEBUG', defaultValue: false, description: 'Enable debug?')
}
pipeline {
agent any
stages {
stage('Print') {
steps {
script {
echo "Environment: ${params.ENV}"
echo "Debug mode: ${params.DEBUG}"
}
}
}
}
}What will be printed if the user selects 'test' for ENV and checks the debug box?
Solution
Step 1: Identify parameter values chosen
User selects 'test' for ENV and checks debug, so DEBUG is true.Step 2: Understand echo output
Echo prints the selected ENV and DEBUG values from params object.Final Answer:
Environment: test Debug mode: true -> Option BQuick Check:
Selected ENV=test, DEBUG=true [OK]
- Assuming default values instead of user choices
- Mixing up ENV values
- Ignoring boolean checkbox state
parameters {
booleanParam(name: 'RUN_TESTS', defaultValue: 'false', description: 'Run tests?')
}When running the job, Jenkins throws an error. What is the problem?
Solution
Step 1: Check booleanParam defaultValue type
defaultValue must be true or false (boolean), not 'false' (string).Step 2: Identify error cause
Passing string 'false' causes type error in Jenkins pipeline.Final Answer:
defaultValue should be a boolean, not a string -> Option AQuick Check:
Boolean defaultValue = true/false, not 'true'/'false' [OK]
- Using string 'false' instead of boolean false
- Thinking parameter names must be lowercase
- Assuming booleanParam needs choice parameter
Solution
Step 1: Match each input to parameter type
Region selection from fixed list -> Choice parameter; version text -> String parameter; yes/no confirm -> Boolean parameter.Step 2: Verify option matches all three correctly
Choice parameter for region, String parameter for version, Boolean parameter for confirmation correctly assigns Choice, String, and Boolean parameters respectively.Final Answer:
Choice parameter for region, String parameter for version, Boolean parameter for confirmation -> Option DQuick Check:
Dropdown = Choice, Text = String, Yes/No = Boolean [OK]
- Mixing parameter types for inputs
- Using Boolean for text input
- Using String for fixed list selection
Ready to prove it?
Pass the test and this pattern moves unknown
