Interview Prep/Jenkins/Scripted pipeline, Groovy & CPS

What is the `script` block in declarative, and what are its limits?

BeginnerConceptScripted pipeline, Groovy & CPS
Answer

script { } embeds scripted Groovy inside a declarative steps block: variables, if, loops, try/catch, calling methods. It is the escape hatch for logic declarative cannot express. Keep it short; if a script block grows beyond ~10 lines or appears in several pipelines, move it into a shared library step. Variables declared with def inside script are local to that block; use env.X to share values across stages.

All Jenkins questions Roadmap: Jenkins

More on Scripted pipeline, Groovy & CPS