Challenge - 5 Problems
Environment Variables Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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}"
}
}
}
}
}Attempts:
2 left
💡 Hint
Remember how environment variables are accessed in Jenkins pipeline scripts using env.
✗ Incorrect
In Jenkins scripted or declarative pipelines, environment variables defined in the environment block are accessed using env.VARIABLE_NAME. Here, env.MY_VAR returns 'hello'.
🧠 Conceptual
intermediate1:30remaining
Understanding environment variable scope in Jenkins
Which statement correctly describes the scope of environment variables defined inside a Jenkins pipeline's environment block?
Attempts:
2 left
💡 Hint
Think about when environment variables are set and how Jenkins shares them.
✗ Incorrect
Environment variables defined in the environment block are set for the entire pipeline run and are accessible in all stages and steps.
❓ Troubleshoot
advanced2: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?
Attempts:
2 left
💡 Hint
Check how shell interprets quotes and variable expansion.
✗ Incorrect
In shell scripts, variables inside single quotes are not expanded. Using double quotes or no quotes allows expansion of environment variables.
🔀 Workflow
advanced2: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?
Attempts:
2 left
💡 Hint
Think about where environment variables must be declared to persist across stages.
✗ Incorrect
Environment variables declared in the pipeline-level environment block are available in all stages. Variables set inside a stage or shell command do not persist to other stages.
✅ Best Practice
expert3: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?
Attempts:
2 left
💡 Hint
Consider how Jenkins manages secrets securely.
✗ Incorrect
The Jenkins Credentials plugin securely stores secrets and injects them into pipelines without exposing them in logs or code.