Issue
- When running my pipeline I am hitting a
Method Code Too Large
error which is causing it to fail
Environment
- CloudBees CI (CloudBees Core) on Modern Cloud Platforms
- CloudBees CI (CloudBees Core) on Traditional Platforms - Client controller
- CloudBees Jenkins Platform - Client controller
- CloudBees Jenkins Distribution
- Jenkins LTS
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:
- 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 - Move sections of the Jenkinsfile code out into their own separate methods by doing a groovy method declaration:
def $METHOD_NAME(arguments...){}
- Use the startup argument
org.jenkinsci.plugins.pipeline.modeldefinition.parser.RuntimeASTTransformer.SCRIPT_SPLITTING_TRANSFORMATION=true
as mentioned in JENKINS-56500
1 Comments