0
0
Jenkinsdevops~5 mins

Environment variables in builds in Jenkins - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an environment variable in Jenkins builds?
An environment variable is a named value that Jenkins makes available to build steps. It helps pass configuration or secrets without hardcoding them in scripts.
Click to reveal answer
beginner
How can you access environment variables in a Jenkins Pipeline script?
You can access environment variables using the syntax env.VARIABLE_NAME inside a Pipeline script.
Click to reveal answer
intermediate
What is the difference between global and build-specific environment variables in Jenkins?
Global environment variables are set for all builds on the Jenkins server, while build-specific variables are set only for a particular build or job.
Click to reveal answer
beginner
How do you define environment variables in a Jenkins Declarative Pipeline?
Use the environment block inside the pipeline or stage to define variables, for example:<br>
environment {
    MY_VAR = 'value'
}
Click to reveal answer
beginner
Why should sensitive data be stored as environment variables instead of hardcoded in Jenkins scripts?
Storing sensitive data as environment variables keeps secrets out of code, making it safer and easier to manage access and updates.
Click to reveal answer
How do you reference an environment variable named 'API_KEY' in a Jenkins Pipeline script?
Aenv.API_KEY
B$API_KEY
Cprocess.env.API_KEY
DgetEnv('API_KEY')
Where can you define environment variables that apply to all Jenkins jobs?
AIn the workspace folder
BInside each build step script
COnly inside the Jenkinsfile
DIn the Jenkins global configuration
Which Jenkins Pipeline block is used to set environment variables?
Atools
Bparameters
Cenvironment
Doptions
Why is it better to use environment variables for secrets in Jenkins builds?
AThey keep secrets out of code and logs
BThey make builds run faster
CThey automatically encrypt data
DThey are easier to hardcode
What happens if you try to access an undefined environment variable in a Jenkins Pipeline?
AIt throws a build error
BIt returns null or empty string
CIt returns the variable name as string
DIt restarts the build
Explain how environment variables are used in Jenkins builds and why they are important.
Think about how you pass information to a recipe without writing it inside the recipe itself.
You got /4 concepts.
    Describe how to set and access environment variables in a Jenkins Declarative Pipeline.
    Imagine labeling ingredients before cooking and then using those labels during cooking.
    You got /4 concepts.