Recall & Review
beginner
What is an environment variable in Jenkins?
An environment variable in Jenkins is a key-value pair that stores information accessible to Jenkins jobs during their execution. It helps configure jobs without hardcoding values.
Click to reveal answer
beginner
How do you access an environment variable in a Jenkins Pipeline script?
You access an environment variable in a Jenkins Pipeline using the syntax:
env.VARIABLE_NAME. For example, env.BUILD_NUMBER gives the current build number.Click to reveal answer
intermediate
How can you set a custom environment variable in a Jenkins Pipeline?
You can set a custom environment variable inside the
environment block in a Jenkins Pipeline like this:<br>environment {
MY_VAR = 'Hello'
}Click to reveal answer
intermediate
What is the difference between global and job-specific environment variables in Jenkins?
Global environment variables are set for all Jenkins jobs and agents, while job-specific variables are defined only within a particular job or pipeline.
Click to reveal answer
intermediate
How do you print all environment variables in a Jenkins Pipeline?
You can print all environment variables using a shell step:<br>
sh 'printenv'<br>or in a scripted pipeline:<br>
env.each { k, v -> println "${k} = ${v}" }Click to reveal answer
How do you access the environment variable named 'PATH' in a Jenkins Pipeline script?
✗ Incorrect
In Jenkins Pipeline, environment variables are accessed using the 'env' object followed by the variable name, like env.PATH.
Where do you define custom environment variables for a Jenkins Pipeline?
✗ Incorrect
Custom environment variables are defined inside the 'environment' block in a Jenkins Pipeline.
Which command prints all environment variables in a Jenkins Pipeline shell step?
✗ Incorrect
The 'printenv' command lists all environment variables in a shell environment.
What is the scope of environment variables defined in the Jenkins global configuration?
✗ Incorrect
Global environment variables are accessible to all Jenkins jobs and agents.
How do you access the current build number in a Jenkins Pipeline?
✗ Incorrect
The current build number is available as the environment variable 'BUILD_NUMBER', accessed via env.BUILD_NUMBER.
Explain how to set and access environment variables in a Jenkins Pipeline.
Think about the environment block and the env object.
You got /3 concepts.
Describe the difference between global and job-specific environment variables in Jenkins.
Consider scope and configuration location.
You got /3 concepts.