Introduction
Script blocks in Groovy let you run multiple commands or complex logic inside Jenkins pipelines. They help you group steps that need to run together or use Groovy features not directly supported by pipeline syntax.
When you want to run several Groovy commands as one unit inside a Jenkins pipeline stage
When you need to use Groovy control structures like loops or conditionals inside your pipeline
When you want to define variables or functions inside your pipeline script
When you want to execute Groovy code that is not part of the declarative pipeline syntax
When you want to manipulate strings, lists, or maps using Groovy methods inside your pipeline