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.
More on Scripted pipeline, Groovy & CPS
What does a scripted pipeline look like and when would you still write one?IntermediateWhat is CPS and why does Jenkins transform pipeline Groovy?AdvancedWhy does `java.io.NotSerializableException` happen in pipelines?AdvancedWhat does `@NonCPS` do and what are its rules?AdvancedWhy do some Groovy closures behave unexpectedly in pipelines, for example `list.each { }` or `sort`?AdvancedHow do you share a variable between stages in declarative?Intermediate