Recall & Review
beginner
What is the purpose of the
environment directive in a Jenkins pipeline?The
environment directive is used to define environment variables that will be available to all steps within the pipeline or stage. It helps set values like paths, credentials, or flags that the build process needs.Click to reveal answer
beginner
How do you define a simple environment variable named
GREETING with the value Hello in a Jenkins declarative pipeline?You define it inside the
environment block like this:<br>environment {
GREETING = 'Hello'
}Click to reveal answer
beginner
Can environment variables defined in the
environment directive be used in shell script steps?Yes, environment variables defined in the
environment directive are accessible inside shell steps. For example, you can use $GREETING in a shell script to get the value.Click to reveal answer
intermediate
What happens if you define an environment variable with the same name in both the pipeline-level and stage-level
environment blocks?The stage-level environment variable overrides the pipeline-level one for that stage only. This allows customizing variables for specific stages.
Click to reveal answer
intermediate
How can you use credentials securely with the
environment directive in Jenkins?You can use the
credentials() helper inside the environment block to inject sensitive data like passwords or tokens securely. For example:<br>environment {
MY_SECRET = credentials('my-credential-id')
}Click to reveal answer
Where do you place the
environment directive in a Jenkins declarative pipeline?✗ Incorrect
The
environment directive is placed inside the pipeline block to apply globally or inside a stage block to apply locally.How do you reference an environment variable named
VERSION inside a shell step?✗ Incorrect
Inside shell scripts, environment variables are accessed with a dollar sign prefix, like
$VERSION.What is the correct syntax to define multiple environment variables in Jenkins pipeline?
✗ Incorrect
Multiple variables are defined inside the environment block separated by new lines without semicolons or commas.
If you want to use a Jenkins credential as an environment variable, which function do you use?
✗ Incorrect
The
credentials() function injects credentials securely into environment variables.What is the scope of environment variables defined inside a stage's
environment block?✗ Incorrect
Stage-level environment variables are limited to that stage's steps.
Explain how the
environment directive works in Jenkins pipelines and how it affects the build steps.Think about how you set variables that all commands can use during the build.
You got /4 concepts.
Describe how to securely use credentials with the
environment directive in Jenkins.Consider how Jenkins manages passwords or tokens safely.
You got /4 concepts.