0
0
Jenkinsdevops~20 mins

Parameterized builds in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Parameterized Builds Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:00remaining
Understanding Parameterized Builds in Jenkins

What is the main purpose of using parameterized builds in Jenkins?

ATo allow users to input values that customize the build process at runtime
BTo create multiple Jenkins jobs with the same configuration
CTo schedule builds to run at fixed times without parameters
DTo automatically deploy builds without any user input
Attempts:
2 left
💡 Hint

Think about how you can make a build flexible by asking for input before it starts.

💻 Command Output
intermediate
1:30remaining
Output of a Parameterized Build with String Parameter

Given a Jenkins pipeline with a string parameter ENV defaulting to dev, what will be the output of the following snippet if the build is triggered with ENV=prod?

pipeline {
  agent any
  parameters {
    string(name: 'ENV', defaultValue: 'dev', description: 'Environment')
  }
  stages {
    stage('Print Env') {
      steps {
        echo "Deploying to ${params.ENV} environment"
      }
    }
  }
}
AError: params.ENV is undefined
BDeploying to dev environment
CDeploying to ${params.ENV} environment
DDeploying to prod environment
Attempts:
2 left
💡 Hint

Remember that parameters override default values when provided at build time.

Configuration
advanced
2:00remaining
Configuring a Boolean Parameter in Jenkins Pipeline

Which of the following Jenkins pipeline snippets correctly defines a boolean parameter named RUN_TESTS with a default value of true?

Aparameters { boolean(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests?') }
Bparameters { booleanParam(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests?') }
Cparameters { boolParam(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests?') }
Dparameters { booleanParameter(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests?') }
Attempts:
2 left
💡 Hint

Check the exact syntax for boolean parameters in Jenkins declarative pipeline.

Troubleshoot
advanced
1:30remaining
Troubleshooting Missing Parameter Value in Jenkins Build

A Jenkins job is configured with a string parameter VERSION. When triggered manually, the build fails with the error groovy.lang.MissingPropertyException: No such property: VERSION. What is the most likely cause?

AThe parameter <code>VERSION</code> was not defined in the pipeline parameters block
BThe parameter <code>VERSION</code> was defined but misspelled in the script as <code>version</code>
CThe build was triggered without selecting the parameter option
DThe Jenkins server is down
Attempts:
2 left
💡 Hint

Think about how Jenkins exposes parameters to the pipeline script.

🔀 Workflow
expert
2:30remaining
Best Workflow to Use Parameters for Conditional Deployment

You want to create a Jenkins pipeline that deploys to different environments based on a parameter DEPLOY_ENV which can be dev, staging, or prod. Which pipeline snippet correctly implements this conditional deployment?

pipeline {
  agent any
  parameters {
    choice(name: 'DEPLOY_ENV', choices: ['dev', 'staging', 'prod'], description: 'Select environment')
  }
  stages {
    stage('Deploy') {
      steps {
        script {
          // Fill in conditional deployment here
        }
      }
    }
  }
}
Awhen { environment name: 'DEPLOY_ENV', value: 'dev' } { echo 'Deploying to dev' }
Bmatch(params.DEPLOY_ENV) { case 'dev' -> echo 'Deploying to dev'; case 'staging' -> echo 'Deploying to staging'; case 'prod' -> echo 'Deploying to prod'; }
Cif (params.DEPLOY_ENV == 'dev') { echo 'Deploying to dev' } else if (params.DEPLOY_ENV == 'staging') { echo 'Deploying to staging' } else { echo 'Deploying to prod' }
Dswitch(params.DEPLOY_ENV) { case 'dev': echo 'Deploying to dev'; break; case 'staging': echo 'Deploying to staging'; break; case 'prod': echo 'Deploying to prod'; break; }
Attempts:
2 left
💡 Hint

Use Groovy script inside the script block to handle conditions.