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.
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`?AdvancedWhat is the `script` block in declarative, and what are its limits?Beginner