Challenge - 5 Problems
Parameter Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of Jenkinsfile with String Parameter
Given this Jenkinsfile snippet, what will be the output when the build is triggered with the default parameter value?
pipeline {
agent any
parameters {
string(name: 'GREETING', defaultValue: 'Hello', description: 'Greeting message')
}
stages {
stage('Print') {
steps {
echo params.GREETING
}
}
}
}Jenkins
pipeline {
agent any
parameters {
string(name: 'GREETING', defaultValue: 'Hello', description: 'Greeting message')
}
stages {
stage('Print') {
steps {
echo params.GREETING
}
}
}
}Attempts:
2 left
💡 Hint
Look at the defaultValue set in the string parameter.
✗ Incorrect
The string parameter GREETING has a default value 'Hello'. If the build is triggered without changing it, params.GREETING will be 'Hello'.
💻 Command Output
intermediate2:00remaining
Boolean Parameter Effect on Build
Consider this Jenkinsfile snippet with a boolean parameter. What will be printed if the build is triggered with the boolean parameter unchecked?
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'
}
}
}
}
}
}Jenkins
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'
}
}
}
}
}
}Attempts:
2 left
💡 Hint
Boolean parameters are true if checked, false if unchecked.
✗ Incorrect
If the boolean parameter DEPLOY is unchecked, params.DEPLOY is false, so the else branch runs printing 'Skipping deploy'.
💻 Command Output
advanced2:00remaining
Choice Parameter Value in Jenkins Pipeline
What will be the output of this Jenkins pipeline if the choice parameter 'ENV' is set to 'staging' when the build starts?
pipeline {
agent any
parameters {
choice(name: 'ENV', choices: ['dev', 'staging', 'prod'], description: 'Select environment')
}
stages {
stage('Show Env') {
steps {
echo "Selected environment is: ${params.ENV}"
}
}
}
}Jenkins
pipeline {
agent any
parameters {
choice(name: 'ENV', choices: ['dev', 'staging', 'prod'], description: 'Select environment')
}
stages {
stage('Show Env') {
steps {
echo "Selected environment is: ${params.ENV}"
}
}
}
}Attempts:
2 left
💡 Hint
The output uses the value of params.ENV which is set by the choice parameter.
✗ Incorrect
The choice parameter ENV is set to 'staging' at build start, so params.ENV equals 'staging'. The echo prints that value.
❓ Troubleshoot
advanced2:00remaining
Troubleshooting Undefined Parameter in Jenkinsfile
A Jenkins pipeline uses a boolean parameter named 'RUN_TESTS'. The pipeline fails with an error:
Options:
groovy.lang.MissingPropertyException: No such property: RUN_TESTS. What is the most likely cause?Options:
Attempts:
2 left
💡 Hint
Check if the parameter is declared properly in the Jenkinsfile.
✗ Incorrect
If the parameter is not declared in the parameters block, params.RUN_TESTS is undefined, causing the MissingPropertyException.
✅ Best Practice
expert3:00remaining
Best Practice for Secure Use of String Parameters
Which practice is best to securely handle sensitive data passed as a string parameter in Jenkins pipelines?
Attempts:
2 left
💡 Hint
Think about how to avoid exposing secrets in logs.
✗ Incorrect
Masking sensitive string parameters using Jenkins credentials or masking plugins prevents secrets from appearing in logs, improving security.