0
0
Jenkinsdevops~20 mins

String, boolean, and choice parameters in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Parameter Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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
      }
    }
  }
}
AHello
BGREETING
Cnull
DError: params.GREETING undefined
Attempts:
2 left
💡 Hint
Look at the defaultValue set in the string parameter.
💻 Command Output
intermediate
2: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'
          }
        }
      }
    }
  }
}
Afalse
BDeploying...
Ctrue
DSkipping deploy
Attempts:
2 left
💡 Hint
Boolean parameters are true if checked, false if unchecked.
💻 Command Output
advanced
2: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}"
      }
    }
  }
}
ASelected environment is: prod
BSelected environment is: staging
CSelected environment is: dev
DSelected environment is: ENV
Attempts:
2 left
💡 Hint
The output uses the value of params.ENV which is set by the choice parameter.
Troubleshoot
advanced
2:00remaining
Troubleshooting Undefined Parameter in Jenkinsfile
A Jenkins pipeline uses a boolean parameter named 'RUN_TESTS'. The pipeline fails with an error: groovy.lang.MissingPropertyException: No such property: RUN_TESTS. What is the most likely cause?

Options:
AThe parameter was not defined in the parameters block of the Jenkinsfile.
BThe parameter name is misspelled in the script as 'RUN_TESTS'.
CBoolean parameters cannot be accessed via params in Jenkins pipelines.
DThe Jenkins agent does not support boolean parameters.
Attempts:
2 left
💡 Hint
Check if the parameter is declared properly in the Jenkinsfile.
Best Practice
expert
3: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?
AUse a string parameter and print its value in the console for debugging.
BStore sensitive data directly in the Jenkinsfile as plain text.
CUse a string parameter but mask its value in the console output using Jenkins credentials binding.
DUse a choice parameter with all possible sensitive values listed.
Attempts:
2 left
💡 Hint
Think about how to avoid exposing secrets in logs.