0
0
Jenkinsdevops~5 mins

Groovy syntax in pipelines in Jenkins - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Adef
Bvar
Clet
Dconst
What does the agent block specify in a Jenkins pipeline?
AThe pipeline stages
BThe machine or environment where the pipeline runs
CThe steps to execute
DThe pipeline triggers
How do you write a conditional statement in Groovy to check if the branch is 'main'?
Aif (BRANCH_NAME === 'main') { ... }
Bif BRANCH_NAME = 'main' then ...
Cif (env.BRANCH_NAME == 'main') { ... }
Dif [ $BRANCH_NAME == 'main' ]
What is the purpose of the script block in a declarative pipeline?
ATo write imperative Groovy code inside declarative syntax
BTo define environment variables
CTo specify the agent
DTo declare pipeline stages
Which step should you use to run a shell command on a Linux agent in Jenkins pipeline?
Apowershell
Bbat
Ccmd
Dsh
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.