Recall & Review
beginner
What is the basic structure of a Jenkins pipeline script using Groovy?
A Jenkins pipeline script typically starts with the
pipeline block, containing agent to specify where to run, and stages with multiple stage blocks defining steps.Click to reveal answer
beginner
How do you define a variable in Groovy within a Jenkins pipeline?
You define a variable using
def keyword, for example: def myVar = 'Hello'. Variables can be used to store values during the pipeline execution.Click to reveal answer
intermediate
What is the purpose of the
script block in a declarative Jenkins pipeline?The
script block allows you to write imperative Groovy code inside a declarative pipeline, enabling complex logic that is not supported directly by declarative syntax.Click to reveal answer
beginner
How do you write a simple conditional statement in Groovy within a Jenkins pipeline?
Use the standard Groovy
if statement, for example:<br>if (env.BRANCH_NAME == 'main') { echo 'On main branch' }.Click to reveal answer
beginner
What is the difference between
sh and bat steps in Jenkins pipelines?sh runs shell commands on Unix/Linux agents, while bat runs batch commands on Windows agents. Both are used to execute system commands from Groovy scripts.Click to reveal answer
Which keyword is used to define a variable in Groovy within a Jenkins pipeline?
✗ Incorrect
In Groovy, variables are defined using the
def keyword.What does the
agent block specify in a Jenkins pipeline?✗ Incorrect
The
agent block tells Jenkins where to run the pipeline or stage.How do you write a conditional statement in Groovy to check if the branch is 'main'?
✗ Incorrect
Groovy uses
if (condition) { } syntax and environment variables are accessed via env.What is the purpose of the
script block in a declarative pipeline?✗ Incorrect
The
script block allows complex Groovy code that declarative syntax does not support.Which step should you use to run a shell command on a Linux agent in Jenkins pipeline?
✗ Incorrect
sh runs shell commands on Unix/Linux agents.Explain how to structure a simple Jenkins pipeline using Groovy syntax.
Think about the main blocks that organize the pipeline.
You got /4 concepts.
Describe how to use variables and conditional statements in Jenkins pipeline Groovy scripts.
Focus on variable declaration and simple if conditions.
You got /4 concepts.