0
0
Jenkinsdevops~20 mins

Parameters block declaration in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 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.