I have Jenkins Pipeline code in jenkisnfile which is 790 lines. I am getting following error message Method code too large
11:05:24 org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
11:05:24 General error during class generation: Method code too large!
11:05:24
11:05:24 java.lang.RuntimeException: Method code too large!
11:05:24 at groovyjarjarasm.asm.MethodWriter.a(Unknown Source)
11:05:24 at groovyjarjarasm.asm.ClassWriter.toByteArray(Unknown Source)
11:05:24 at org.codehaus.groovy.control.CompilationUnit$17.call(CompilationUnit.java:827)
11:05:24 at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1065)
11:05:24 at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
11:05:24 at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
11:05:24 at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
11:05:24 at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
11:05:24 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
11:05:24 at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
11:05:24 at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
11:05:24 at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
11:05:24 at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
11:05:24 at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:571)
11:05:24 at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:523)
11:05:24 at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337)
11:05:24 at hudson.model.ResourceController.execute(ResourceController.java:97)
11:05:24 at hudson.model.Executor.run(Executor.java:429)
11:05:24
11:05:24 1 error
11:05:24
11:05:24 at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
11:05:24 at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
11:05:24 at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
11:05:24 at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
11:05:24 at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
11:05:24 at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
11:05:24 at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
11:05:24 at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
11:05:24 at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
11:05:24 at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
11:05:24 at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
11:05:24 at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:571)
11:05:24 at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:523)
11:05:24 at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337)
11:05:24 at hudson.model.ResourceController.execute(ResourceController.java:97)
11:05:24 at hudson.model.Executor.run(Executor.java:429)
11:05:24 Finished: FAILURE
Using following versions
OS : Ubuntu 18.04.1
Jenkins : 2.263.4
Java : 1.8.0_181
( Master & Slave )
Set JAVA_ARGS="-Xmx2048m"
in /etc/default/jenkins
( Master )
How can I fix this ?
Java has a 64K size limit on bytecode. It is not an issue with Jenkins. To solve this, you should break apart your pipeline into methods. There is a great example here.