Interview Prep/Jenkins/Scripted pipeline, Groovy & CPS

What does the `Method code too large!` error mean and how do you avoid it?

AdvancedConceptScripted pipeline, Groovy & CPS
Answer

The JVM limits a single method's bytecode to 64 KB. A declarative pipeline is compiled into one large method, so very long Jenkinsfiles with many stages, big matrix blocks or long inline scripts exceed the limit and fail at compile time. Fixes: move logic into shared library steps, replace repeated stages with a matrix or a generated parallel, move long sh scripts into files in the repo, and split one giant pipeline into several jobs. Enabling org.jenkinsci.plugins.pipeline.modeldefinition.parser.RuntimeASTTransformer.SCRIPT_SPLITTING_TRANSFORMATION=true helps in many cases.

All Jenkins questions Roadmap: Jenkins

More on Scripted pipeline, Groovy & CPS