Challenge - 5 Problems
Environment Variable Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
Jenkins environment variable usage in shell step
In a Jenkins pipeline, you have set an environment variable
MY_VAR with value hello. What will be the output of the following shell step?sh 'echo $MY_VAR'
Jenkins
pipeline {
agent any
environment {
MY_VAR = 'hello'
}
stages {
stage('Print') {
steps {
sh 'echo $MY_VAR'
}
}
}
}Attempts:
2 left
💡 Hint
Remember how shell variables are accessed inside shell steps in Jenkins.
✗ Incorrect
In Jenkins shell steps, environment variables are accessed using the shell syntax with a dollar sign, so $MY_VAR expands to 'hello'.
🧠 Conceptual
intermediate1:30remaining
Scope of environment variables in Jenkins pipeline
Which statement about environment variables in Jenkins declarative pipelines is true?
Attempts:
2 left
💡 Hint
Think about where you declare environment variables in a declarative pipeline.
✗ Incorrect
The
environment block in a declarative pipeline sets variables that are available throughout the pipeline's stages and steps.❓ Troubleshoot
advanced2:00remaining
Why does a Jenkins shell step not see a custom environment variable?
You set an environment variable
MY_VAR inside a script block using env.MY_VAR = 'test'. But when you run sh 'echo $MY_VAR' in the next step, it prints empty. Why?Attempts:
2 left
💡 Hint
Consider how Jenkins passes environment variables to shell steps.
✗ Incorrect
Setting
env.MY_VAR inside a script block changes the variable for the Groovy environment but does not export it to the shell environment automatically.🔀 Workflow
advanced2:00remaining
Passing environment variables between Jenkins pipeline stages
You want to set an environment variable
VERSION in one stage and use it in a later stage. Which approach works correctly?Attempts:
2 left
💡 Hint
Think about how Jenkins pipeline stages run in separate processes.
✗ Incorrect
Each stage runs in a separate process, so environment variables set in one stage do not persist automatically. Writing to a file and reading it later is a common way to share data.
✅ Best Practice
expert2:30remaining
Secure handling of sensitive environment variables in Jenkins builds
Which is the best practice to handle sensitive environment variables like passwords in Jenkins pipelines?
Attempts:
2 left
💡 Hint
Think about security and Jenkins features for secrets.
✗ Incorrect
Jenkins Credentials plugin securely stores secrets and allows injecting them without exposing in logs or code.