0
0
Jenkinsdevops~20 mins

Environment variables access in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Environment Variables Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Accessing environment variables in a Jenkins pipeline
What will be the output of the following Jenkins pipeline script snippet?
Jenkins
pipeline {
  agent any
  environment {
    MY_VAR = 'hello'
  }
  stages {
    stage('Print') {
      steps {
        script {
          echo "Value is: ${env.MY_VAR}"
        }
      }
    }
  }
}
AValue is: hello
BValue is: ${MY_VAR}
CValue is:
DError: MY_VAR not defined
Attempts:
2 left
💡 Hint
Remember how environment variables are accessed in Jenkins pipeline scripts using env.
🧠 Conceptual
intermediate
1:30remaining
Understanding environment variable scope in Jenkins
Which statement correctly describes the scope of environment variables defined inside a Jenkins pipeline's environment block?
AThey are available only after the pipeline finishes.
BThey are available throughout the entire pipeline run.
CThey are available only to the shell commands but not to Groovy scripts.
DThey are available only within the stage where they are defined.
Attempts:
2 left
💡 Hint
Think about when environment variables are set and how Jenkins shares them.
Troubleshoot
advanced
2:00remaining
Troubleshooting missing environment variable in Jenkins shell step
A Jenkins pipeline defines an environment variable MY_SECRET in the environment block. However, when running a shell step, the variable is empty. What is the most likely cause?
AJenkins does not support environment variables in shell steps.
BThe environment variable was not defined in the environment block.
CThe shell step uses single quotes around the variable reference, preventing expansion.
DThe variable name is case-insensitive and was misspelled.
Attempts:
2 left
💡 Hint
Check how shell interprets quotes and variable expansion.
🔀 Workflow
advanced
2:30remaining
Passing environment variables between Jenkins pipeline stages
Which method correctly passes an environment variable set in one stage to another stage in a Jenkins declarative pipeline?
ASet the variable in the environment block at the pipeline level.
BUse the 'withEnv' step inside each stage separately.
CSet the variable inside a stage's script block and access it directly in the next stage.
DUse 'sh export VAR=value' in one stage and access VAR in the next stage shell step.
Attempts:
2 left
💡 Hint
Think about where environment variables must be declared to persist across stages.
Best Practice
expert
3:00remaining
Secure handling of sensitive environment variables in Jenkins
What is the recommended best practice to securely use sensitive environment variables like passwords in Jenkins pipelines?
APrint sensitive variables in console logs for debugging.
BStore sensitive values directly in the pipeline script environment block.
CHardcode secrets in shell commands inside the pipeline.
DUse Jenkins Credentials plugin and access secrets via credentials binding.
Attempts:
2 left
💡 Hint
Consider how Jenkins manages secrets securely.