Bird
Raised Fist0
Jenkinsdevops~20 mins

Parameters block declaration in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Parameters Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Jenkins pipeline snippet?
Consider this Jenkins pipeline snippet with a parameters block. What will be the value of the parameter DEPLOY_ENV when the pipeline starts?
Jenkins
pipeline {
  agent any
  parameters {
    string(name: 'DEPLOY_ENV', defaultValue: 'staging', description: 'Deployment environment')
  }
  stages {
    stage('Print') {
      steps {
        echo "Deploying to ${params.DEPLOY_ENV}"
      }
    }
  }
}
ADeploying to staging
BDeploying to production
CDeploying to null
DPipeline fails with error
Attempts:
2 left
💡 Hint
Look at the defaultValue set in the string parameter.
❓ Configuration
intermediate
2:00remaining
Which parameters block correctly declares a boolean parameter named 'RUN_TESTS' with default true?
Select the correct Jenkins pipeline parameters block snippet that declares a boolean parameter RUN_TESTS with a default value of true.
A
parameters {
  booleanParam(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests?')
}
B
parameters {
  boolean(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests?')
}
C
parameters {
  boolParam(name: 'RUN_TESTS', default: true, description: 'Run tests?')
}
D
parameters {
  booleanParam('RUN_TESTS', true, 'Run tests?')
}
Attempts:
2 left
💡 Hint
Check the exact method name and parameter names for boolean parameters in Jenkins.
❓ Troubleshoot
advanced
2:00remaining
Why does this parameters block cause a syntax error?
Identify the reason for the syntax error in this Jenkins pipeline parameters block snippet.
Jenkins
parameters {
  choice(name: 'ENV', choices: 'dev\nstaging\nprod', description: 'Select environment')
  string(name: 'VERSION', defaultValue: '1.0')
}
AMissing description for the string parameter causes syntax error
BParameters block must be inside stages block
CChoices string must be a list, not a single string with newlines
DChoice parameter name must be uppercase only
Attempts:
2 left
💡 Hint
Look at the type expected for the choices argument in choice parameter.
🔀 Workflow
advanced
2:00remaining
In which stage does the parameter get evaluated in this Jenkins pipeline?
Given this Jenkins pipeline, when is the parameter BUILD_TYPE evaluated and available for use?
Jenkins
pipeline {
  agent any
  parameters {
    choice(name: 'BUILD_TYPE', choices: ['debug', 'release'], description: 'Build type')
  }
  stages {
    stage('Build') {
      steps {
        echo "Building ${params.BUILD_TYPE}"
      }
    }
  }
}
AOnly inside the Build stage steps
BParameters are evaluated after all stages finish
CAfter the Build stage completes
DAt pipeline start, before any stage runs
Attempts:
2 left
💡 Hint
Parameters are used to configure the pipeline before it runs.
✅ Best Practice
expert
3:00remaining
What is the recommended way to declare multiple parameters of different types in Jenkins pipeline?
Choose the best parameters block declaration that includes a string, boolean, and choice parameter correctly.
A
parameters {
  stringParam('APP_VERSION', '1.0', 'App version')
  boolParam('ENABLE_FEATURE', false, 'Enable feature')
  choiceParam('DEPLOY_ENV', ['dev', 'qa', 'prod'], 'Deployment environment')
}
B
parameters {
  string(name: 'APP_VERSION', defaultValue: '1.0', description: 'App version')
  booleanParam(name: 'ENABLE_FEATURE', defaultValue: false, description: 'Enable feature')
  choice(name: 'DEPLOY_ENV', choices: ['dev', 'qa', 'prod'], description: 'Deployment environment')
}
C
parameters {
  string(name: 'APP_VERSION', default: '1.0', description: 'App version')
  boolean(name: 'ENABLE_FEATURE', defaultValue: false, description: 'Enable feature')
  choice(name: 'DEPLOY_ENV', choices: 'dev\nqa\nprod', description: 'Deployment environment')
}
D
parameters {
  string(name: 'APP_VERSION', defaultValue: '1.0')
  booleanParam(name: 'ENABLE_FEATURE', defaultValue: false)
  choice(name: 'DEPLOY_ENV', choices: 'dev,qa,prod', description: 'Deployment environment')
}
Attempts:
2 left
💡 Hint
Check the exact parameter method names and argument names for each type.

Practice

(1/5)
1. What is the purpose of the parameters block in a Jenkins pipeline?
easy
A. To define inputs that users can provide before the job runs
B. To specify the stages of the pipeline
C. To set environment variables for the pipeline
D. To declare the agent where the pipeline runs

Solution

  1. Step 1: Understand the role of the parameters block

    The parameters block is used to ask users for input before the pipeline starts.
  2. Step 2: Compare with other pipeline blocks

    Other blocks like stages define pipeline steps, environment sets variables, and agent defines the execution node.
  3. Final Answer:

    To define inputs that users can provide before the job runs -> Option A
  4. Quick Check:

    parameters block = user inputs [OK]
Hint: Parameters block = user input before job runs [OK]
Common Mistakes:
  • Confusing parameters with stages
  • Thinking parameters set environment variables
  • Mixing parameters with agent declaration
2. Which of the following is the correct syntax to declare a string parameter named VERSION in a Jenkins pipeline?
easy
A. parameters { param string VERSION = '1.0' }
B. parameters { string VERSION = '1.0' }
C. parameters { string(name: 'VERSION', defaultValue: '1.0', description: 'Version number') }
D. parameters { string VERSION: '1.0' }

Solution

  1. Step 1: Recall correct string parameter syntax

    The correct syntax uses string(name: 'NAME', defaultValue: 'value', description: 'text').
  2. Step 2: Check each option

    parameters { string(name: 'VERSION', defaultValue: '1.0', description: 'Version number') } matches the correct syntax. The other options use invalid or incorrect syntax.
  3. Final Answer:

    parameters { string(name: 'VERSION', defaultValue: '1.0', description: 'Version number') } -> Option C
  4. Quick Check:

    Correct string param syntax = parameters { string(name: 'VERSION', defaultValue: '1.0', description: 'Version number') } [OK]
Hint: Use string(name: 'NAME', defaultValue: '', description: '') [OK]
Common Mistakes:
  • Using assignment (=) inside parameters block
  • Omitting parameter name key
  • Incorrect parameter declaration keywords
3. Given this Jenkins pipeline snippet:
pipeline {
  agent any
  parameters {
    booleanParam(name: 'DEPLOY', defaultValue: true, description: 'Deploy to production?')
  }
  stages {
    stage('Check') {
      steps {
        script {
          if (params.DEPLOY) {
            echo 'Deploying...'
          } else {
            echo 'Skipping deploy'
          }
        }
      }
    }
  }
}

What will Jenkins print if the user selects false for DEPLOY?
medium
A. Deploying...
B. No output
C. Error: DEPLOY parameter not found
D. Skipping deploy

Solution

  1. Step 1: Understand booleanParam usage

    The parameter DEPLOY is a boolean with default true, but user selects false.
  2. Step 2: Follow the if condition in script

    If params.DEPLOY is true, it prints 'Deploying...'; else it prints 'Skipping deploy'. Since user chose false, it prints 'Skipping deploy'.
  3. Final Answer:

    Skipping deploy -> Option D
  4. Quick Check:

    params.DEPLOY false = 'Skipping deploy' [OK]
Hint: Boolean param false triggers else branch [OK]
Common Mistakes:
  • Assuming defaultValue always used ignoring user input
  • Confusing parameter name case sensitivity
  • Expecting error when parameter is valid
4. Identify the error in this parameters block:
parameters {
  choice(name: 'ENV', choices: 'dev\nstaging\nprod', description: 'Select environment')
  string(name: 'TAG', default: 'latest', description: 'Docker tag')
}
medium
A. The choices string should use commas instead of newlines
B. The string parameter uses 'default' instead of 'defaultValue'
C. The choice parameter name must be uppercase
D. Parameters block cannot have multiple parameters

Solution

  1. Step 1: Check choice parameter syntax

    Choice parameter uses a newline-separated string for choices, which is correct.
  2. Step 2: Check string parameter syntax

    String parameter must use 'defaultValue', not 'default'. This causes a syntax error.
  3. Final Answer:

    The string parameter uses 'default' instead of 'defaultValue' -> Option B
  4. Quick Check:

    String param defaultValue key required [OK]
Hint: Use defaultValue, not default, for string parameters [OK]
Common Mistakes:
  • Using 'default' instead of 'defaultValue'
  • Misformatting choices string
  • Assuming parameter names must be uppercase
5. You want to create a Jenkins pipeline that asks the user to select multiple branches to build from a list, but Jenkins does not have a built-in multi-select parameter. How can you simulate this using the parameters block?
hard
A. Use a string parameter where the user enters branch names separated by commas
B. Use multiple boolean parameters, one for each branch
C. Use a choice parameter with multiple selections enabled
D. Use a password parameter to hide branch names

Solution

  1. Step 1: Understand Jenkins parameter limitations

    Jenkins does not support multi-select choice parameters natively.
  2. Step 2: Find workaround using string parameter

    Using a string parameter, users can input multiple branch names separated by commas, which the pipeline can parse.
  3. Step 3: Evaluate other options

    Multiple booleans are cumbersome for many branches; choice parameter does not support multi-select; password parameter hides input but is unrelated.
  4. Final Answer:

    Use a string parameter where the user enters branch names separated by commas -> Option A
  5. Quick Check:

    Simulate multi-select with string input [OK]
Hint: Use comma-separated string input for multi-select simulation [OK]
Common Mistakes:
  • Expecting multi-select choice parameter exists
  • Using many booleans for many options
  • Misusing password parameter for 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