Bird
Raised Fist0
Jenkinsdevops~5 mins

String, boolean, and choice parameters in Jenkins - Commands & Configuration

Choose your learning style10 modes available
Introduction
Jenkins parameters let you ask users for input before running a job. String, boolean, and choice parameters help customize the job run without changing the code.
When you want to let users enter a text value like a version number before the job starts
When you want to give users a simple yes/no option to enable or disable a feature
When you want users to pick one option from a list, like selecting an environment to deploy to
When you want to reuse the same job for different inputs without making multiple jobs
When you want to make your Jenkins jobs interactive and flexible
Config File - Jenkinsfile
Jenkinsfile
pipeline {
  agent any
  parameters {
    string(name: 'VERSION', defaultValue: '1.0', description: 'Enter the version number')
    booleanParam(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests before build?')
    choice(name: 'ENVIRONMENT', choices: ['dev', 'staging', 'production'], description: 'Select deployment environment')
  }
  stages {
    stage('Show Parameters') {
      steps {
        echo "Version: ${params.VERSION}"
        echo "Run Tests: ${params.RUN_TESTS}"
        echo "Environment: ${params.ENVIRONMENT}"
      }
    }
  }
}

This Jenkinsfile defines a pipeline with three parameters:

  • string: lets the user enter a text value, here a version number.
  • booleanParam: lets the user choose true or false, here to run tests or not.
  • choice: lets the user pick one option from a list, here the deployment environment.

The pipeline then prints the chosen values in the first stage.

Commands
This command updates the Jenkins job with the Jenkinsfile that includes the parameters. It makes the parameters available when you run the job.
Terminal
jenkins-jobs --conf jenkins.ini update Jenkinsfile
Expected OutputExpected
Job updated successfully
This command runs the Jenkins job named 'my-job' using the Jenkins CLI. It passes values for the string, boolean, and choice parameters to customize the job run.
Terminal
java -jar jenkins-cli.jar -s http://localhost:8080 build my-job -p VERSION=2.1 -p RUN_TESTS=false -p ENVIRONMENT=staging
Expected OutputExpected
[Pipeline] Start of Pipeline [Pipeline] echo Version: 2.1 [Pipeline] echo Run Tests: false [Pipeline] echo Environment: staging [Pipeline] End of Pipeline Finished: SUCCESS
→
-p - Pass parameter values to the job
This command runs the Jenkins job without passing parameters, so default values from the Jenkinsfile are used.
Terminal
java -jar jenkins-cli.jar -s http://localhost:8080 build my-job
Expected OutputExpected
[Pipeline] Start of Pipeline [Pipeline] echo Version: 1.0 [Pipeline] echo Run Tests: true [Pipeline] echo Environment: dev [Pipeline] End of Pipeline Finished: SUCCESS
Key Concept

If you remember nothing else from this pattern, remember: Jenkins parameters let users customize job runs by entering text, choosing yes/no, or picking from a list before the job starts.

Common Mistakes
Not defining parameters in the Jenkinsfile but trying to pass them when running the job
Jenkins won't recognize parameters that are not declared, so the job will ignore passed values or fail.
Always declare all parameters in the Jenkinsfile under the parameters block before using them.
Passing parameter values with wrong names or typos
Jenkins will ignore unknown parameter names and use defaults, causing unexpected behavior.
Use exact parameter names as declared in the Jenkinsfile when passing values.
Using choice parameter values not listed in the choices array
Jenkins will reject invalid choices and the job may fail or use defaults.
Only pass values that are included in the choices list defined in the Jenkinsfile.
Summary
Define string, boolean, and choice parameters in the Jenkinsfile to ask users for input before running a job.
Use the Jenkins CLI to run jobs and pass parameter values to customize the job execution.
If no parameters are passed, Jenkins uses the default values defined in the Jenkinsfile.

Practice

(1/5)
1. What type of Jenkins parameter should you use if you want the user to enter any text value before running a job?
easy
A. String parameter
B. Boolean parameter
C. Choice parameter
D. File parameter

Solution

  1. Step 1: Understand parameter types

    String parameters allow users to input any text value.
  2. Step 2: Match requirement to parameter

    Since the question asks for text input, String parameter fits best.
  3. Final Answer:

    String parameter -> Option A
  4. Quick Check:

    Text input = String parameter [OK]
Hint: Text input? Always pick String parameter [OK]
Common Mistakes:
  • Choosing Boolean parameter for text input
  • Confusing Choice parameter with String parameter
  • Selecting File parameter which is for files
2. Which of the following is the correct syntax to define a Boolean parameter in a Jenkins pipeline script?
easy
A. choice(name: 'DEPLOY', choices: ['true', 'false'], description: 'Deploy to production?')
B. stringParam(name: 'DEPLOY', defaultValue: 'true', description: 'Deploy to production?')
C. booleanParam(name: 'DEPLOY', defaultValue: true, description: 'Deploy to production?')
D. boolParam(name: 'DEPLOY', default: true, desc: 'Deploy to production?')

Solution

  1. Step 1: Recall Jenkins Boolean parameter syntax

    The correct syntax uses booleanParam with name, defaultValue, and description keys.
  2. Step 2: Compare options

    booleanParam(name: 'DEPLOY', defaultValue: true, description: 'Deploy to production?') matches the correct syntax exactly; others have wrong names or keys.
  3. Final Answer:

    booleanParam(name: 'DEPLOY', defaultValue: true, description: 'Deploy to production?') -> Option C
  4. Quick Check:

    Boolean parameter syntax = booleanParam(name: 'DEPLOY', defaultValue: true, description: 'Deploy to production?') [OK]
Hint: Boolean param uses booleanParam() with defaultValue [OK]
Common Mistakes:
  • Using stringParam for boolean values
  • Incorrect parameter function names like boolParam
  • Passing boolean as string instead of boolean type
3. Given this Jenkins pipeline snippet:
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?
medium
A. Environment: prod Debug mode: false
B. Environment: test Debug mode: true
C. Environment: test Debug mode: false
D. Environment: dev Debug mode: true

Solution

  1. Step 1: Identify parameter values chosen

    User selects 'test' for ENV and checks debug, so DEBUG is true.
  2. Step 2: Understand echo output

    Echo prints the selected ENV and DEBUG values from params object.
  3. Final Answer:

    Environment: test Debug mode: true -> Option B
  4. Quick Check:

    Selected ENV=test, DEBUG=true [OK]
Hint: Echo prints exactly chosen parameter values [OK]
Common Mistakes:
  • Assuming default values instead of user choices
  • Mixing up ENV values
  • Ignoring boolean checkbox state
4. You wrote this Jenkins pipeline snippet:
parameters {
  booleanParam(name: 'RUN_TESTS', defaultValue: 'false', description: 'Run tests?')
}

When running the job, Jenkins throws an error. What is the problem?
medium
A. defaultValue should be a boolean, not a string
B. Parameter name cannot be uppercase
C. booleanParam does not accept description
D. Missing choice parameter for boolean

Solution

  1. Step 1: Check booleanParam defaultValue type

    defaultValue must be true or false (boolean), not 'false' (string).
  2. Step 2: Identify error cause

    Passing string 'false' causes type error in Jenkins pipeline.
  3. Final Answer:

    defaultValue should be a boolean, not a string -> Option A
  4. Quick Check:

    Boolean defaultValue = true/false, not 'true'/'false' [OK]
Hint: Boolean defaultValue must be true or false, no quotes [OK]
Common Mistakes:
  • Using string 'false' instead of boolean false
  • Thinking parameter names must be lowercase
  • Assuming booleanParam needs choice parameter
5. You want to create a Jenkins job that asks the user to select a deployment region from ['us-east', 'us-west', 'eu-central'], enter a version string, and confirm with a yes/no checkbox before deploying. Which parameter types should you use together?
hard
A. Choice parameter for region, Choice parameter for version, Boolean parameter for confirmation
B. String parameter for region, Boolean parameter for version, Choice parameter for confirmation
C. Boolean parameter for region, Choice parameter for version, String parameter for confirmation
D. Choice parameter for region, String parameter for version, Boolean parameter for confirmation

Solution

  1. Step 1: Match each input to parameter type

    Region selection from fixed list -> Choice parameter; version text -> String parameter; yes/no confirm -> Boolean parameter.
  2. 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.
  3. Final Answer:

    Choice parameter for region, String parameter for version, Boolean parameter for confirmation -> Option D
  4. Quick Check:

    Dropdown = Choice, Text = String, Yes/No = Boolean [OK]
Hint: Dropdown = Choice, Text input = String, Checkbox = Boolean [OK]
Common Mistakes:
  • Mixing parameter types for inputs
  • Using Boolean for text input
  • Using String for fixed list selection
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard