Bird
Raised Fist0
Jenkinsdevops~20 mins

Dynamic parameter values in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Dynamic Parameter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Dynamic Parameter Values in Jenkins

In Jenkins, dynamic parameters allow parameter values to be generated at build time. Which of the following best describes how dynamic parameter values are typically generated?

ABy manually entering parameter values each time the build runs
BBy hardcoding all parameter values in the Jenkinsfile before the build starts
CBy using a Groovy script or external script to generate parameter values when the build is triggered
DBy setting static environment variables in the Jenkins global configuration
Attempts:
2 left
💡 Hint

Think about how Jenkins can run scripts to fetch or calculate values just before the build starts.

💻 Command Output
intermediate
1:30remaining
Output of a Groovy Script for Dynamic Parameters

Given the following Groovy script used in a Jenkins Active Choices parameter to generate a list of branches from a Git repository, what is the expected output?

Jenkins
def branches = ['main', 'develop', 'feature-x']
return branches
A['main', 'develop', 'feature-x']
Bmain, develop, feature-x
CError: Missing return statement
Dnull
Attempts:
2 left
💡 Hint

The script returns a list object directly.

❓ Configuration
advanced
2:00remaining
Configuring a Dynamic Choice Parameter in Jenkinsfile

Which Jenkinsfile snippet correctly defines a dynamic choice parameter that lists files in the workspace directory at build time?

Aproperties([parameters([choice(name: 'FILES', choices: sh(script: 'ls', returnStdout: true), description: 'Select a file')])])
Bproperties([parameters([activeChoiceParam(name: 'FILES') { script { return ['file1', 'file2'] } }])])
Cproperties([parameters([choice(name: 'FILES', choices: ['file1', 'file2'], description: 'Select a file')])])
Dproperties([parameters([activeChoiceParam(name: 'FILES') { script { return sh(script: 'ls', returnStdout: true).split('\n') } }])])
Attempts:
2 left
💡 Hint

Look for the option that uses a script to dynamically list files at build time.

❓ Troubleshoot
advanced
1:30remaining
Troubleshooting Dynamic Parameter Script Failure

A Jenkins Active Choices parameter script that queries an external API to generate options suddenly fails with a timeout error. What is the most likely cause?

AThe script syntax is invalid and causes a compilation error
BThe Jenkins agent does not have network access to the external API
CThe parameter name is missing in the Jenkinsfile
DThe Jenkins master is offline
Attempts:
2 left
💡 Hint

Consider connectivity issues when scripts call external services.

🔀 Workflow
expert
2:30remaining
Implementing a Multi-Level Dynamic Parameter Workflow

You want to create a Jenkins job with two dynamic parameters: the first lists available projects, and the second lists branches for the selected project. Which workflow correctly implements this multi-level dynamic parameter setup?

AUse two Active Choices parameters where the second parameter's script reads the first parameter's value and queries branches accordingly
BUse two static choice parameters with hardcoded project and branch lists
CUse a single parameter that combines project and branch names in one list
DUse environment variables to pass project and branch names between builds
Attempts:
2 left
💡 Hint

Think about how one parameter can depend on another's value dynamically.

Practice

(1/5)
1. What is the main purpose of using dynamic parameter values in Jenkins jobs?
easy
A. To update input options based on other inputs or external data
B. To make Jenkins jobs run faster
C. To disable user inputs during job execution
D. To automatically restart failed jobs

Solution

  1. Step 1: Understand dynamic parameters

    Dynamic parameters change their available options based on other inputs or external data sources.
  2. Step 2: Identify the purpose

    This makes Jenkins jobs flexible and user-friendly by showing relevant choices dynamically.
  3. Final Answer:

    To update input options based on other inputs or external data -> Option A
  4. Quick Check:

    Dynamic parameters update options dynamically [OK]
Hint: Dynamic parameters change options based on other inputs [OK]
Common Mistakes:
  • Thinking dynamic parameters speed up job execution
  • Confusing dynamic parameters with job restart features
  • Assuming dynamic parameters disable inputs
2. Which Jenkins plugin is commonly used to create dynamic parameter values based on a script?
easy
A. Pipeline Plugin
B. Git Plugin
C. Active Choices Plugin
D. Mailer Plugin

Solution

  1. Step 1: Identify plugins for dynamic parameters

    The Active Choices Plugin allows parameters to be dynamically generated using Groovy scripts.
  2. Step 2: Exclude unrelated plugins

    Git Plugin manages source control, Pipeline Plugin manages job pipelines, and Mailer Plugin sends emails, none create dynamic parameters.
  3. Final Answer:

    Active Choices Plugin -> Option C
  4. Quick Check:

    Active Choices Plugin enables dynamic parameters [OK]
Hint: Active Choices Plugin supports scripted dynamic parameters [OK]
Common Mistakes:
  • Choosing Git Plugin for dynamic parameters
  • Confusing Pipeline Plugin with parameter plugins
  • Selecting Mailer Plugin unrelated to parameters
3. Given this Groovy script for an Active Choices parameter:
return ['dev', 'test', 'prod'].findAll { it.startsWith(params.ENV_PREFIX ?: '') }

What will be the parameter options if ENV_PREFIX is set to t?
medium
A. ['dev', 'test', 'prod']
B. ['test']
C. ['prod']
D. []

Solution

  1. Step 1: Understand the script filtering

    The script returns list items starting with the value of ENV_PREFIX. Here, ENV_PREFIX is 't'.
  2. Step 2: Filter the list

    From ['dev', 'test', 'prod'], only 'test' starts with 't'.
  3. Final Answer:

    ['test'] -> Option B
  4. Quick Check:

    Filter by prefix 't' gives ['test'] [OK]
Hint: Filter list by prefix to find matching options [OK]
Common Mistakes:
  • Ignoring the prefix filter and returning full list
  • Choosing empty list when prefix matches an item
  • Selecting wrong matching item
4. You wrote this Active Choices script:
return ['one', 'two', 'three'].filter { it.contains(params.SEARCH) }

But Jenkins shows a syntax error. What is the problem?
medium
A. The parameter SEARCH must be declared as a string
B. The list should be a map, not a list
C. The script must use double quotes for strings
D. The method should be findAll instead of filter

Solution

  1. Step 1: Check Groovy list filtering methods

    Groovy uses findAll to filter lists, not filter which causes syntax error.
  2. Step 2: Confirm other parts are correct

    The list syntax and parameter usage are valid; string quotes can be single or double.
  3. Final Answer:

    The method should be findAll instead of filter -> Option D
  4. Quick Check:

    Use findAll for filtering lists in Groovy [OK]
Hint: Use findAll, not filter, to filter lists in Groovy [OK]
Common Mistakes:
  • Using filter instead of findAll causes syntax errors
  • Thinking list must be a map for filtering
  • Believing quotes type causes syntax error
5. You want a Jenkins job parameter that lists all Git branches dynamically from a repository URL. Which approach correctly implements this dynamic parameter?
hard
A. Use Active Choices Plugin with a Groovy script that runs git ls-remote --heads <repo_url> and parses branch names
B. Use a String parameter and ask users to type branch names manually
C. Use a Boolean parameter to select if branches should be listed
D. Use a fixed Choice parameter with hardcoded branch names

Solution

  1. Step 1: Identify dynamic branch listing method

    Active Choices Plugin with Groovy script can run shell commands to fetch live branch names from Git.
  2. Step 2: Exclude static or unrelated options

    String parameter requires manual input, Boolean parameter is not for listing, fixed Choice is static and not dynamic.
  3. Final Answer:

    Use Active Choices Plugin with a Groovy script that runs git ls-remote --heads <repo_url> and parses branch names -> Option A
  4. Quick Check:

    Active Choices + git command fetches dynamic branches [OK]
Hint: Use Active Choices with git command to list branches dynamically [OK]
Common Mistakes:
  • Using static parameters instead of dynamic scripts
  • Choosing Boolean parameter for listing options
  • Forgetting to parse git command output
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