Challenge - 5 Problems
Environment Directive Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Jenkins pipeline environment variable?
Consider this Jenkins pipeline snippet:
What will be printed in the console output?
pipeline {
agent any
environment {
GREETING = 'Hello'
TARGET = 'World'
}
stages {
stage('Print') {
steps {
script {
echo "${GREETING}, ${TARGET}!"
}
}
}
}
}What will be printed in the console output?
Jenkins
pipeline {
agent any
environment {
GREETING = 'Hello'
TARGET = 'World'
}
stages {
stage('Print') {
steps {
script {
echo "${GREETING}, ${TARGET}!"
}
}
}
}
}Attempts:
2 left
💡 Hint
Remember that environment variables defined in the environment block are accessible inside steps using ${VARIABLE_NAME}.
✗ Incorrect
The environment directive sets variables that are accessible in the pipeline steps. Using ${GREETING} and ${TARGET} inside echo will substitute their values.
❓ Configuration
intermediate2:00remaining
Which environment directive syntax correctly sets a variable with a shell command output?
You want to set an environment variable CURRENT_DATE to the output of the shell command date in a Jenkins pipeline environment block. Which option correctly does this?
Attempts:
2 left
💡 Hint
In Jenkins declarative pipeline, environment variables cannot directly run shell commands. You must use a script block or special syntax.
✗ Incorrect
Only option B uses the correct syntax to run a shell command and assign its trimmed output to an environment variable in a declarative pipeline.
❓ Troubleshoot
advanced2:00remaining
Why does this environment variable not get set as expected?
Given this Jenkins pipeline snippet:
The output shows only the default PATH, not '/custom/path'. Why?
pipeline {
agent any
environment {
PATH = '/custom/path'
}
stages {
stage('Check') {
steps {
sh 'echo $PATH'
}
}
}
}The output shows only the default PATH, not '/custom/path'. Why?
Jenkins
pipeline {
agent any
environment {
PATH = '/custom/path'
}
stages {
stage('Check') {
steps {
sh 'echo $PATH'
}
}
}
}Attempts:
2 left
💡 Hint
Some environment variables like PATH are treated specially by Jenkins for security reasons.
✗ Incorrect
Jenkins resets PATH in shell steps to avoid security risks. Overriding PATH in environment does not affect shell steps unless explicitly handled.
🔀 Workflow
advanced2:00remaining
How to pass environment variables between stages in a declarative pipeline?
You want to set an environment variable in one stage and use it in a later stage in a Jenkins declarative pipeline. Which approach works?
Attempts:
2 left
💡 Hint
Environment variables defined at the pipeline level are global to all stages.
✗ Incorrect
Only environment variables defined at the pipeline level environment block are available in all stages. Stage-level environment blocks are local to that stage.
✅ Best Practice
expert2:00remaining
What is the best practice for securely handling sensitive environment variables in Jenkins pipelines?
You need to use a secret API key in your Jenkins pipeline environment. Which method is the best practice to handle this securely?
Attempts:
2 left
💡 Hint
Avoid exposing secrets in code or logs. Use Jenkins built-in secure storage.
✗ Incorrect
Using Jenkins credentials and credentials binding plugin securely injects secrets as environment variables without exposing them in code or logs.