Recall & Review
beginner
What is a script block in Groovy within Jenkins pipelines?
A script block is a section inside a Jenkins pipeline where you can write Groovy code directly. It allows you to run complex logic that is not supported by the declarative pipeline syntax.
Click to reveal answer
beginner
How do you define a script block in a Jenkins declarative pipeline?
You define a script block using the
script { } keyword inside a stage or step. For example:<br>stage('Example') {
steps {
script {
// Groovy code here
}
}
}Click to reveal answer
beginner
Why use script blocks in Jenkins pipelines?
Script blocks let you use Groovy features like loops, conditionals, and variables that are not available in declarative syntax. This helps you write flexible and powerful pipeline logic.Click to reveal answer
intermediate
Can you use variables declared inside a script block outside of it in Jenkins pipelines?
No, variables declared inside a script block are local to that block. To share data outside, you need to declare variables at the pipeline or stage level.
Click to reveal answer
intermediate
What happens if you put complex Groovy code outside a script block in a declarative pipeline?
The pipeline will fail to run because declarative syntax only supports limited Groovy expressions. Complex code must be inside a script block to execute properly.
Click to reveal answer
What keyword starts a script block in a Jenkins declarative pipeline?
✗ Incorrect
The
script keyword is used to start a script block where Groovy code can be written.Where can you place a script block in a Jenkins declarative pipeline?
✗ Incorrect
Script blocks must be inside a stage's steps section to run Groovy code.
What is a common reason to use script blocks in Jenkins pipelines?
✗ Incorrect
Script blocks allow complex Groovy code that declarative syntax cannot handle.
What happens if you try to use a variable declared inside a script block outside it?
✗ Incorrect
Variables inside script blocks have local scope and are not accessible outside.
Which of these is NOT true about script blocks?
✗ Incorrect
Script blocks must be inside a stage's steps section; they cannot be used anywhere.
Explain what a script block is in Jenkins pipelines and why it is useful.
Think about how you add custom code inside a mostly fixed pipeline structure.
You got /4 concepts.
Describe the scope of variables declared inside a script block and how to share data outside it.
Consider where variables live and how to pass data between parts of the pipeline.
You got /4 concepts.