Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define an environment variable named GREETING with value 'Hello'.
Jenkins
pipeline {
agent any
environment {
GREETING = [1]
}
stages {
stage('Example') {
steps {
echo "${GREETING}, World!"
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the value causes syntax errors.
Using unquoted words is invalid in environment directive.
✗ Incorrect
Environment variable values must be strings enclosed in quotes. Here, "Hello" is the correct string value.
2fill in blank
mediumComplete the code to set an environment variable PATH_EXT to '/usr/local/bin'.
Jenkins
pipeline {
agent any
environment {
PATH_EXT = [1]
}
stages {
stage('Show Path') {
steps {
sh 'echo $PATH_EXT'
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the path string.
Adding trailing slash when not intended.
✗ Incorrect
The environment variable value must be a string enclosed in quotes. Double quotes "" are commonly used.
3fill in blank
hardFix the error in the environment directive to correctly set JAVA_HOME to '/usr/lib/jvm/java-11-openjdk'.
Jenkins
pipeline {
agent any
environment {
JAVA_HOME = [1]
}
stages {
stage('Build') {
steps {
sh 'echo $JAVA_HOME'
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Missing quotes around the path causes syntax errors.
Using single quotes sometimes works but double quotes are safer.
✗ Incorrect
The value must be a string enclosed in quotes. Double quotes "" are preferred for paths in Jenkins environment directive.
4fill in blank
hardFill both blanks to set environment variables USER_NAME to 'admin' and USER_ROLE to 'developer'.
Jenkins
pipeline {
agent any
environment {
USER_NAME = [1]
USER_ROLE = [2]
}
stages {
stage('Print') {
steps {
echo "User: ${USER_NAME}, Role: ${USER_ROLE}"
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the values for USER_NAME and USER_ROLE.
Forgetting quotes around the values.
✗ Incorrect
USER_NAME should be "admin" and USER_ROLE should be "developer", both as quoted strings.
5fill in blank
hardFill all three blanks to set environment variables APP_ENV to 'production', APP_VERSION to '1.2.3', and DEBUG_MODE to 'false'.
Jenkins
pipeline {
agent any
environment {
APP_ENV = [1]
APP_VERSION = [2]
DEBUG_MODE = [3]
}
stages {
stage('Info') {
steps {
echo "Environment: ${APP_ENV}, Version: ${APP_VERSION}, Debug: ${DEBUG_MODE}"
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted values causes errors.
Mixing up the variable values.
✗ Incorrect
APP_ENV is "production", APP_VERSION is "1.2.3", and DEBUG_MODE is "false". All must be quoted strings.