Method Code Too Large Error

Article ID:360039361371
1 minute readKnowledge base

Issue

  • When running my pipeline I am hitting a Method Code Too Large error which is causing it to fail

Explanation

This issue is caused by Java itself having a limit on the size of a single method and declarative pipelines wrapping a single Jenkinsfile into one method behind the scenes. This issue is discussed in JENKINS-37984 and applies to code between the brackets in the declarative syntax pipeline{}

Resolution

Here are some potential options to resolve this issue:

  1. Limit the size of the Jenkinsfile code inside of the brackets by moving code out to shared libraries, or external scripts you call with a sh './myscript' command, as per Pipeline Best Practices

  2. Move sections of the Jenkinsfile code out into their own separate methods by doing a groovy method declaration: def $METHOD_NAME(arguments...){}

  3. Use the startup argument org.jenkinsci.plugins.pipeline.modeldefinition.parser.RuntimeASTTransformer.SCRIPT_SPLITTING_TRANSFORMATION=true as mentioned in JENKINS-56500