0
0
Jenkinsdevops~5 mins

Environment variables access in Jenkins - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AgetEnv('PATH')
BPATH.env
Cenv.PATH
Denvironment.PATH
Where do you define custom environment variables for a Jenkins Pipeline?
AInside the environment block
BIn the Jenkins global config only
CInside the steps block
DIn the Jenkinsfile header comment
Which command prints all environment variables in a Jenkins Pipeline shell step?
Alistenv
Bprintenv
Cshowenv
Denvlist
What is the scope of environment variables defined in the Jenkins global configuration?
AOnly available during build steps
BOnly available to one job
COnly available in post-build actions
DAvailable to all jobs and agents
How do you access the current build number in a Jenkins Pipeline?
Aenv.BUILD_NUMBER
Bbuild.number
CcurrentBuild.number
Denv.BUILDNUM
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.