[JIRA] (JENKINS-37984) org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during class generation: Method code too large! error in pipeline Script

1,685 views
Skip to first unread message

deep.anu98@yahoo.co.in (JIRA)

unread,
Sep 6, 2016, 9:38:04 AM9/6/16
to jenkinsc...@googlegroups.com
Anudeep Lalam created an issue
 
Jenkins / Bug JENKINS-37984
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during class generation: Method code too large! error in pipeline Script
Issue Type: Bug Bug
Assignee: Jesse Glick
Components: pipeline
Created: 2016/Sep/06 1:37 PM
Priority: Blocker Blocker
Reporter: Anudeep Lalam

Hi,

We are getting below error in Pipeline which has some 495 lines of groovy code. Initially we assumed that one of our methods has an issue but once we remove any 30-40 lines of Pipeline groovy, this issue is not coming.

Can you please suggest a quick workaround. It's a blocker for us.

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during class generation: Method code too large!

java.lang.RuntimeException: Method code too large!
	at groovyjarjarasm.asm.MethodWriter.a(Unknown Source)
	at groovyjarjarasm.asm.ClassWriter.toByteArray(Unknown Source)
	at org.codehaus.groovy.control.CompilationUnit$16.call(CompilationUnit.java:815)
	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1053)
	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:67)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:410)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:373)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:213)
	at hudson.model.ResourceController.execute(ResourceController.java:98)
	at hudson.model.Executor.run(Executor.java:410)

1 error

	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1073)
	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:67)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:410)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:373)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:213)
	at hudson.model.ResourceController.execute(ResourceController.java:98)
	at hudson.model.Executor.run(Executor.java:410)
Finished: FAILURE
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

pete.mcnab@gmail.com (JIRA)

unread,
Oct 13, 2016, 4:38:03 PM10/13/16
to jenkinsc...@googlegroups.com
Pete McNab commented on Bug JENKINS-37984
 
Re: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during class generation: Method code too large! error in pipeline Script

I'm ran into the same problem. I have a large (200kb) pipeline script that is generated from our legacy build specification language.

My generated code is broken up into stages, with each stage running a potentially large parallel pipeline operation, where each platform of a given target is built.

I attempted to break it up by having each stage be defined as a method and calling the method rather than just having all the code in one giant block, but it didn't help.

As this will impact a lot of people trying to migrate to the Jenkins pipeline, and may make them throw up their hands due to the error being vague and unhelpful (which I realize is not the fault of Jenkins, but the underlying Java/Groovy architecture, it might be good to have some specific guides on how to deal with this.

pete.mcnab@gmail.com (JIRA)

unread,
Oct 13, 2016, 4:53:01 PM10/13/16
to jenkinsc...@googlegroups.com
Pete McNab edited a comment on Bug JENKINS-37984
I' m ran ve run into the same problem.  I have a large ( 200kb 200+kb ) pipeline script that is generated from our legacy build specification language.  


My generated code is broken up into stages, with each stage running a potentially large parallel pipeline operation, where each platform of a given target is built.

After some googling about the underlying cause, I attempted to break it up by having each stage be defined as a method and calling the method rather than just having all the code in one giant block, but it didn't help.  


As this will impact a lot of people trying to migrate to the Jenkins pipeline, and may make them throw up their hands due to the error being vague and unhelpful (which I realize is not the fault of Jenkins, but the underlying Java/Groovy architecture, it might be good to have some specific guides on how to deal with this.

jglick@cloudbees.com (JIRA)

unread,
Oct 13, 2016, 5:20:03 PM10/13/16
to jenkinsc...@googlegroups.com
Jesse Glick assigned an issue to Unassigned
 

Surprised that breaking it up into separate methods did not help. Other than that, I have no suggestions offhand.

Change By: Jesse Glick
Component/s: workflow-cps-plugin
Component/s: pipeline
Assignee: Jesse Glick

pete.mcnab@gmail.com (JIRA)

unread,
Oct 13, 2016, 5:38:05 PM10/13/16
to jenkinsc...@googlegroups.com
Pete McNab edited a comment on Bug JENKINS-37984
 
Re: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during class generation: Method code too large! error in pipeline Script
I've run into the same problem.  I have a large (200+kb) pipeline script that is generated from our legacy build specification language.  


My generated code is broken up into stages, with each stage running a potentially large parallel pipeline operation, where each platform of a given target is built.

After some googling about the underlying cause, I attempted to break it up by having each stage be defined as a method and calling the method rather than just having all the code in one giant block, but it didn't help.  

As this will impact a lot of people trying to migrate to the Jenkins pipeline, and may make them throw up their hands due to the error being vague and unhelpful (which I realize is not the fault of Jenkins, but the underlying Java/Groovy architecture ) , it might be good to have some specific guides on how to deal with this.

pete.mcnab@gmail.com (JIRA)

unread,
Oct 13, 2016, 6:00:01 PM10/13/16
to jenkinsc...@googlegroups.com

Yeah it's kind of puzzling – as part of my testing I had reduced the number of stages significantly.

So a version that worked had 4 stages with no methods and it was about 1720 lines.

With the full set of stages (27), the number of lines is about 5300 lines. Breaking it up into methods had no method larger than about 450 lines, but it wouldn't run.

I also went in and removed the 4 stages that had worked, which put the entire script down to ~3600 lines broken out into methods, and that wouldn't run either.

pete.mcnab@gmail.com (JIRA)

unread,
Oct 13, 2016, 6:06:02 PM10/13/16
to jenkinsc...@googlegroups.com

Whoops. Well cancel what I said. When I generated the code with what I intended to be methods I was actually defining closures attached to a variable, and now it's happy with it.

So more specifically, for those of you who find this, what I used to have was:

stage foo
parallel([
... giant list of maps ...
])

What I changed it to was:

stage foo
def build_foo() {
parallel([
...giant list of maps...
])
build_foo()

pete.mcnab@gmail.com (JIRA)

unread,
Oct 13, 2016, 6:07:03 PM10/13/16
to jenkinsc...@googlegroups.com
Pete McNab edited a comment on Bug JENKINS-37984
Whoops.  Well cancel what I said.  When I generated the code with what I intended to be methods I was actually defining closures attached to a variable, and now it's happy with it.

So more specifically, for those of you who find this, what I used to have was:
{noformat}
stage foo
parallel([
... giant list of maps ...
])
{noformat}
What I changed it to was:

{noformat}
stage foo
def build_foo() {
  parallel([
     ...giant list of maps...
  ])
build_foo()
{noformat}

pete.mcnab@gmail.com (JIRA)

unread,
Oct 13, 2016, 6:07:05 PM10/13/16
to jenkinsc...@googlegroups.com

pete.mcnab@gmail.com (JIRA)

unread,
Oct 13, 2016, 6:30:03 PM10/13/16
to jenkinsc...@googlegroups.com
Pete McNab edited a comment on Bug JENKINS-37984
Whoops.  Well cancel what I said.  When I generated the code with what I intended to be methods I was actually defining closures attached to a variable , and now . When I did it properly as methods it 's happy ok with it.


So more specifically, for those of you who find this, what I used to have was:
{noformat}
stage foo
parallel([
... giant list of maps ...
])
{noformat}
What I changed it to was:

{noformat}
stage foo
def build_foo() {
  parallel([
     ...giant list of maps...
  ])}
build_foo()
{noformat}

jglick@cloudbees.com (JIRA)

unread,
Oct 13, 2016, 7:11:01 PM10/13/16
to jenkinsc...@googlegroups.com

pete.mcnab@gmail.com (JIRA)

unread,
Oct 14, 2016, 2:52:04 PM10/14/16
to jenkinsc...@googlegroups.com

I made one – I still think this case should be touched on in the Pipeline docs. I don't think searching Jira or StackOverflow is a substitute for documentation

jglick@cloudbees.com (JIRA)

unread,
Oct 14, 2016, 4:44:01 PM10/14/16
to jenkinsc...@googlegroups.com

philippe.lancon@sercel.fr (JIRA)

unread,
Feb 7, 2017, 8:10:02 AM2/7/17
to jenkinsc...@googlegroups.com
philippe lançon commented on Bug JENKINS-37984
 
Re: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during class generation: Method code too large! error in pipeline Script

problem seems to be linked with the size all the script but I remarked it's linked also according number and size of stages.
A workaround consists to declare a function called in some big stages.

before :

stage ('build')

{ .... if ..... } else {
}
.....
}

workaround

def build() { .... if ..... }

else {
}
.....
}
stage ('build')

{ build() }

philippe.lancon@sercel.fr (JIRA)

unread,
Feb 7, 2017, 8:11:01 AM2/7/17
to jenkinsc...@googlegroups.com
philippe lançon edited a comment on Bug JENKINS-37984
problem seems to be linked with the size all the script but I remarked it's linked also according number and size of stages.
A workaround consists to declare a function called in some big stages.

before :

stage ('build') {
    ....
    if ( ..... ) {
   } else {
   }
  .....
}

workaround

def build() {
    ....
    if ( ..... ) {
   } else {
   }
  .....
}
stage ('build') {
   build()
}

ruud.prijs@gmail.com (JIRA)

unread,
Mar 2, 2018, 9:11:02 AM3/2/18
to jenkinsc...@googlegroups.com
Ruud P commented on Bug JENKINS-37984

I brake up the code but it did not help, so what i am doing wrong here? Anny solution available?

 

oringinal:

stages {
stage('Test') {
parallel {
    stage(bla1t') {
      when {expression bla}}
        steps {node(label: 'bla') {test('bla', '')}}}

    stage(bla1t') {
      when {expression bla}}
        steps {node(label: 'bla') {test('bla', '')}}}

    stage(bla1t') {
      when {expression bla}}
        steps {node(label: 'bla') {test('bla', '')}}}

    stage(bla1t') {
      when {expression bla}}
        steps {node(label: 'bla') {test('bla', '')}}}

     ..... more as 200

 

change it into:

stages {
   stage('Test') { maintest()}

(in the same file i defined a function maintest with all the parallel stages)

def maintest()

parallel {

   stage(bla1t') {
      when {expression bla}}
        steps {node(label: 'bla') {test('bla', '')}}}

    stage(bla1t') {
      when {expression bla}}
        steps {node(label: 'bla') {test('bla', '')}}}

    stage(bla1t') {
      when {expression bla}}
        steps {node(label: 'bla') {test('bla', '')}}}

    stage(bla1t') {
      when {expression bla}}
        steps {node(label: 'bla') {test('bla', '')}}}

     ..... more as 200

 

 

This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

ruud.prijs@gmail.com (JIRA)

unread,
Mar 14, 2018, 6:58:04 AM3/14/18
to jenkinsc...@googlegroups.com

llibicpep@gmail.com (JIRA)

unread,
Apr 5, 2018, 9:00:06 AM4/5/18
to jenkinsc...@googlegroups.com
Dmytro Kryvenko commented on Bug JENKINS-37984
 
Re: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during class generation: Method code too large! error in pipeline Script

Any workarounds? My scenario is quite specific, we threat Jenkinsfile as some sort of a JIT. No one working with it directly, it rather being generated automatically based on something else. It is essential for the debugging purposes to have a big picture perspective on how the resulting Jenkinsfile going to look like, and there is no benefits into splitting it or moving to the shared library (again this is not for humans and not made by humans).

We need a way to increase this limit.

ruud.prijs@gmail.com (JIRA)

unread,
Apr 5, 2018, 9:06:02 AM4/5/18
to jenkinsc...@googlegroups.com
Ruud P commented on Bug JENKINS-37984

i use as "work a round" a script blok, for me it was a lot of work to change it but the result was smaller code witch is always good

ruud.prijs@gmail.com (JIRA)

unread,
Apr 5, 2018, 9:08:01 AM4/5/18
to jenkinsc...@googlegroups.com
Ruud P edited a comment on Bug JENKINS-37984
i use as "work a round" a script blok, for me it was a lot of work to change it but the result was smaller code witch is always good


 

  stages \{
    stage('parallel stages') \{
      steps \{
        script \{

ruud.prijs@gmail.com (JIRA)

unread,
Apr 5, 2018, 10:02:02 AM4/5/18
to jenkinsc...@googlegroups.com
Ruud P edited a comment on Bug JENKINS-37984
i use as "work a round" a script blok, for me it was a lot of work to change it but the result was smaller code witch is always good

 


  stages \{
    stage('parallel stages') \{
      steps \{
        script \{


in my case i have 200-300 parallel  stages

i generate the parallel stages with a single function and i execute more as 200-300 stages in parallel, this is very dynamic as this amount of stages depends on user input. So i use now script block to generate all the stages and execute the stages instead of using declarative Pipeline.

 

llibicpep@gmail.com (JIRA)

unread,
Apr 5, 2018, 2:16:03 PM4/5/18
to jenkinsc...@googlegroups.com

The thing is I actually don't want to hide this code to the library. My library already does it's thing, I have a custom DSL syntax that my library goes through and generates resulting Jenkinsfile. And I follow TDD, so I got tests, and my tests basically checking the resulting Jenkinsfile vs given my own DSL. Hiding parts of Jenkinsfile into the library going to ruin the whole idea of testing for my project.

llibicpep@gmail.com (JIRA)

unread,
Apr 5, 2018, 2:17:03 PM4/5/18
to jenkinsc...@googlegroups.com
Dmytro Kryvenko edited a comment on Bug JENKINS-37984
The thing is I actually don't want to hide this code to the library. My library already does it's thing, I have a custom DSL syntax that my library goes through and generates resulting Jenkinsfile. And I follow TDD, so I got tests, and my tests basically checking the resulting Jenkinsfile vs given my own DSL. Hiding parts of Jenkinsfile into the library going to ruin the whole idea of testing for my project. Again the Jenkinsfile for me is kind of JIT, it's not a code to being read or created by human.

ryankuba@gmail.com (JIRA)

unread,
Jul 13, 2018, 10:02:03 PM7/13/18
to jenkinsc...@googlegroups.com

I am running into this, example file: 

https://pastebin.com/raw/eS76F1FE

If I rip out some env declaration blocks like: 

         script{
           env.CI_IMAGE = env.DEV_DOCKERHUB_IMAGE
           env.CI_TAGS = env.EXT_RELEASE + '-pkg-' + env.PACKAGE_TAG + '-dev-' + env.COMMIT_SHA
           env.CI_META_TAG = env.EXT_RELEASE + '-pkg-' + env.PACKAGE_TAG + '-dev-' + env.COMMIT_SHA
         }

It will compile up and run, I already tried to move every script section out to functions, but still get Method to Large. 

 

This is only ~800 lines and even if you compiled this text 10x over it would not be at the 64k java limit. 

I am trying to understand how the workflow is interpreted that could result in this limit being hit.  

This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

ryankuba@gmail.com (JIRA)

unread,
Jul 13, 2018, 10:42:02 PM7/13/18
to jenkinsc...@googlegroups.com
Ryan Kuba edited a comment on Bug JENKINS-37984
I am running into this, example file: 

[ https://pastebin.com/raw/ eS76F1FE] fnKnYiMq

If I rip out some env declaration blocks like: 


{code:java}

         script{
           env.CI_IMAGE = env.DEV_DOCKERHUB_IMAGE
           env.CI_TAGS = env.EXT_RELEASE + '-pkg-' + env.PACKAGE_TAG + '-dev-' + env.COMMIT_SHA
           env.CI_META_TAG = env.EXT_RELEASE + '-pkg-' + env.PACKAGE_TAG + '-dev-' + env.COMMIT_SHA
         }
{code}

It will compile up and run, I already tried to move every script section out to functions, but still get Method to Large. 

 

This is only ~800 lines and even if you compiled this text 10x over it would not be at the 64k java limit. 

I am trying to understand how the workflow is interpreted that could result in this limit being hit.  

kabakv@gmail.com (JIRA)

unread,
Aug 11, 2018, 4:33:02 AM8/11/18
to jenkinsc...@googlegroups.com

sz2804@gmail.com (JIRA)

unread,
Sep 5, 2018, 5:45:02 AM9/5/18
to jenkinsc...@googlegroups.com

Hello Guys,

I am trying to find a workaround but after some testing I am not able to determine how Jenkinsfile is being parsed in case of Scripted Pipeline. For me it seems that whole file is going to JVM at once, thus gives this limitation of 800-900 lines of code like mentioned above. I tried to artificially split the code into different node blocks which uses the same runners like:

node('master'){ stage stage stage }
node('master'){ stage stage stage }
node('master'){ stage stage stage }

but it makes no difference. Is there any way to modify code structure so it would be compiled in chunks? Am I able to load some other Jenkinsfiles dynamically? Or maybe it is possible to move some code to shared groovy libraries (but then I would need to call http request plugin from libraries, which I don't know whether is possible)?

I also did some additional, maybe even stupid test to check how many instructions is too much to compile and I was shocked a bit, when I saw ArrayIndexOutOfBoundsException when I had something above 400 print's invoked in the code divided into 3 stages. Is it that the instructions are held on stack and then send to JVM? How come declarative pipeline is so easy to be split and scripted version is not?

I would very much appreciate any workaround to move on with dev.

Best Regards,

Szymon

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

sz2804@gmail.com (JIRA)

unread,
Sep 6, 2018, 6:48:03 AM9/6/18
to jenkinsc...@googlegroups.com

It may sound obvious, however it worked for me when I extracted some methods of reusable code in Jenkinsfile and those are compiled in such a way that I can put more code into those. I don't know where my fixation came from, but I thought that methods are only available in declarative pipeline whereas in scripted pipeline it should be moved to for instance shared libraries. So now my code structure looks like this:

node('master'){
   stage('setup')

{ some logic    method1()    method2()    }

   stage('cleanup')

{ some logic    method2()    method3()    }

}

def method1() {}
def method2() {}
def method3() {}

henryborchers@yahoo.com (JIRA)

unread,
Sep 18, 2018, 10:49:02 AM9/18/18
to jenkinsc...@googlegroups.com

I'm starting to run into this issue myself when my pipeline reaches about 800 lines. I've been creating helper function outside of the "pipeline" brackets and that's helping but I find myself still running into this issue more than I'd like.

I can't help it. Having all the new nice features makes me write longer more useful pipelines.

llibicpep@gmail.com (JIRA)

unread,
Sep 18, 2018, 11:10:07 AM9/18/18
to jenkinsc...@googlegroups.com
Dmytro Kryvenko edited a comment on Bug JENKINS-37984
800 lines of code in one file sounds bad in any language. It definitely needs a refactoring and shared libraries.

Just to be clear - in my case above I experienced that issue while already having my libraries, and it was due the way I designed these libraries (they treat Jenkinsfile concept as some sort of JIT, they basically doing some calculations based on the input and spits out resulting long Jenkinsfile that I then eval() ed). I solved my case by splitting what I eval() into chunks exchanging the data through the context singleton object in my library (surprisingly singleton instances were not per Jenkins master JVM but per library instance, i.e. per individual build). So technically my case wasn't even related to Jenkins at all. I was sending too long string into eval() method and it was legitimately (accordingly to JVM) giving me a finger. Just to give an example, my chunks would look like:

{code:java}
getContext('stages')['Test Stage'] = {
    echo 'hi'
}
{code}

{code:java}
getContext('stages')['Second Test Stage'] = {
  echo 'hi again'

{code}

{code:java}
getContext('stages')['Second Test Stage'] = {
  echo 'hi again'

{code}

{code:java}
timestamps {
    ansiColor("xterm") {
        stage('Test Stage', getContext('stages')['Test Stage'])
        stage('Second Test Stage', getContext('stages')['Second Test Stage'])
    }
}
{code}

Given that I think this issue may be closed now.

llibicpep@gmail.com (JIRA)

unread,
Sep 18, 2018, 11:10:09 AM9/18/18
to jenkinsc...@googlegroups.com

800 lines of code sounds bad in any language. It definitely needs a refactoring and shared libraries.

Just to be clear - in my case above I experienced that issue while already having my libraries, and it was due the way I designed these libraries (they treat Jenkinsfile concept as some sort of JIT, they basically doing some calculations based on the input and spits out resulting long Jenkinsfile that I then eval() ed). I solved my case by splitting what I eval() into chunks exchanging the data through the context singleton object in my library (surprisingly singleton instances were not per Jenkins master JVM but per library instance, i.e. per individual build). So technically my case wasn't even related to Jenkins at all. I was sending too long string into eval() method and it was legitimately (accordingly to JVM) giving me a finger. Just to give an example, my chunks would look like:

getContext('stages')['Test Stage'] = {
    echo 'hi'
}
getContext('stages')['Second Test Stage'] = {
  echo 'hi again'
getContext('stages')['Second Test Stage'] = {
  echo 'hi again'
timestamps {
    ansiColor("xterm") {
        stage('Test Stage', getContext('stages')['Test Stage'])
        stage('Second Test Stage', getContext('stages')['Second Test Stage'])
    }
}

Given that I think this issue may be closed now.

llibicpep@gmail.com (JIRA)

unread,
Sep 18, 2018, 11:12:02 AM9/18/18
to jenkinsc...@googlegroups.com
Dmytro Kryvenko edited a comment on Bug JENKINS-37984
800 lines of code in one file sounds bad in any language. It definitely needs a refactoring and shared libraries.


Just to be clear - in my case above I experienced that issue while already having my libraries, and it was due the way I designed these libraries (they treat Jenkinsfile concept as some sort of JIT, they basically doing some calculations based on the input and spits out resulting long Jenkinsfile that I then eval() ed). I solved my case by splitting what I eval() into chunks exchanging the data through the context singleton object in my library (surprisingly singleton instances were not per Jenkins master JVM but per library instance, i.e. per individual build). So technically my case wasn't even related to Jenkins at all. I was sending too long string into eval() method and it was legitimately (accordingly to JVM) giving me a finger. Just to give an example, my chunks would look like:

{code:java}

getContext('stages')['Test Stage'] = {
    echo 'hi'
}
{code}

{code:java}

getContext('stages')['Second Test Stage'] = {
  echo 'hi again'

{code}

{code:java}
getContext('stages')['Second Test Stage'] = {
  echo 'hi again'

{code}

{code:java}
timestamps {
    ansiColor("xterm") {
        stage('Test Stage', getContext('stages')['Test Stage'])
        stage('Second Test Stage', getContext('stages')['Second Test Stage'])
    }
}
{code}


Given that I think this issue may be closed now.

henryborchers@yahoo.com (JIRA)

unread,
Sep 18, 2018, 5:20:11 PM9/18/18
to jenkinsc...@googlegroups.com

Dmytro Kryvenko, My pipeline is long because it contains more than just unit testing. It's a complete DevOps pipeline with optional stages depending on the situation. I have sequential stages, parallel stages and most of these have a post section that cleans up or depends on the success or failure of the stage. It's very declarative and pretty easy to reason with so there really shouldn't be a reason to refactored the code.

Jenkins has become very very powerful tool with the Pipeline DSL with a lot of very useful features. It's a shame when I when I can't use a feature because my pipeline contains too many lines already.

llibicpep@gmail.com (JIRA)

unread,
Sep 18, 2018, 5:33:02 PM9/18/18
to jenkinsc...@googlegroups.com

Henry Borchers, complexity of your pipeline is completely irrelevant. Just to draw a parallel, the fact that you're creating complex Enterprise product does not justify you to put all it's code in a single file, or even in a single method, does it?

Parts of your pipeline has to be a reusable functions in the shared library, so your actual jenkins file should consist only simple statements, something like

doThis()
if (itsTrue()) {
  doThat()
}

That applies only for scripted pipelines, of course. Accordingly to https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-declarative-pipelines it sounds like declarative pipelines even more limited that I thought, so I'm happy I don't use 'em.

llibicpep@gmail.com (JIRA)

unread,
Sep 18, 2018, 5:46:04 PM9/18/18
to jenkinsc...@googlegroups.com

llibicpep@gmail.com (JIRA)

unread,
Sep 18, 2018, 5:50:02 PM9/18/18
to jenkinsc...@googlegroups.com
Dmytro Kryvenko edited a comment on Bug JENKINS-37984
[~henryborchers], complexity of your pipeline is completely irrelevant. Just to draw a parallel, the fact that you're creating complex Enterprise product does not justify you to put all it's code in a single file, or even in a single method, does it?


Parts of your pipeline has to be a reusable functions in the shared library, so your actual jenkins file should consist only simple statements, something like

{code}
doThis()
if (itsTrue()) {
  doThat()
}
{code}

That applies only for scripted pipelines, of course. Accordingly to https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-declarative-pipelines it sounds like declarative pipelines even more limited
that than I thought, so I'm happy I don't use 'em.

henryborchers@yahoo.com (JIRA)

unread,
Sep 19, 2018, 10:39:07 AM9/19/18
to jenkinsc...@googlegroups.com

Henry Borchers, complexity of your pipeline is completely irrelevant.

Couldn't agree more

Just to draw a parallel, the fact that you're creating complex Enterprise product does not justify you to put all it's code in a single file, or even in a single method, does it?

It's not a complex Enterprise product. Quite the opposite. I don't have much support so I have to automate as much DevOps stuff myself. Because I have very little resources and stakeholders that require a lot, I'm making the most of the resources I can get my hands on.

Parts of your pipeline has to be a reusable functions in the shared library, so your actual jenkins file should consist only simple statements, something like

doThis()
if (itsTrue()) {
  doThat()
}

That applies only for scripted pipelines, of course. Accordingly to https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-declarative-pipelines it sounds like declarative pipelines even more limited than I thought, so I'm happy I don't use 'em.

 

I'm happy that you're happy that you don't use declarative pipelines. However, I do. The only limit I've run has been line length.

Just a quick searching in google reveal there is actually an open source project doing something good enough to demonstrate what I mean:
https://github.com/fabric8io/fabric8-pipeline-library
https://github.com/fabric8io/fabric8-jenkinsfile-library

Yes. I already use shared libraries for somethings already.  I just don't use need it very often.

 

The only reason my pipelines are so long is because of the declarative style.

 

 

stage("Run Doctest Tests"){
  when { 
      equals expected: true, actual: params.TEST_DOCTEST  
  }  
  steps{
      bat "pipenv run sphinx-build -b doctest docs\\source build\\docs -d build\\docs\\doctrees -v"  
  }
  post{ 
      always {
         dir(reports){ 
             archiveArtifacts artifacts: "doctest.txt"
         }
     }
  }
}

 

 

It's more verbose but I find it highly readable and very easy to maintain. Shared libraries are nice for helpers but they can be a pain for maintain so I keep them simple. 

llibicpep@gmail.com (JIRA)

unread,
Sep 19, 2018, 12:05:08 PM9/19/18
to jenkinsc...@googlegroups.com

I don't have much support so I have to automate as much DevOps stuff myself. Because I have very little resources and stakeholders that require a lot, I'm making the most of the resources I can get my hands on.

That is somewhat twisted conclusion. Shared library as a layer of abstraction helps to maintain and simplify your life, as long as you use it right. Same as the possibility to run unit tests for that code. Otherwise it's just a snowflake, it may look beautiful from a certain angle but that is your first symptom you're getting right there.

However, it's a pointless discussion, I am just a user the same as you, I do not making that call, but even then I don't see what Jenkins can possibly do as this is a JVM limitation. The Jenkinsfile essentially is Groovy DSL file which ends up being executed as a method. I can imagine they could possibly do some semantic analysis and try to automatically split it into chunks or obfuscate parts of it into a separate functions, but the level of effort needs to be put in it is nowhere close to the potential benefit. So I wouldn't suggest expecting any resolution to that issue.

llibicpep@gmail.com (JIRA)

unread,
Sep 19, 2018, 12:06:02 PM9/19/18
to jenkinsc...@googlegroups.com
Dmytro Kryvenko edited a comment on Bug JENKINS-37984
{quote}I don't have much support so I have to automate as much DevOps stuff myself. Because I have very little resources and stakeholders that require a lot, I'm making the most of the resources I can get my hands on.{quote}


That is somewhat twisted conclusion. Shared library as a layer of abstraction helps to maintain and simplify your life, as long as you use it right. Same as the possibility to run unit tests for that code. Otherwise it's just a snowflake, it may look beautiful from a certain angle but that is your first symptom you're getting right there.

However, it's a pointless discussion, I am just a user the same as you, I do not making that call, but even then I don't see what Jenkins can possibly do as this is a JVM limitation. The Jenkinsfile essentially is Groovy DSL file which ends up being executed as a method. I can imagine they could possibly do some semantic analysis and try to automatically split it into chunks or obfuscate parts of it into a separate functions, but the level of effort needs to be put in it is nowhere close to the potential benefit. So I wouldn't suggest expecting expect any resolution to that issue.

stephen.tunney@gmail.com (JIRA)

unread,
Sep 20, 2018, 12:03:02 PM9/20/18
to jenkinsc...@googlegroups.com

I have a specific example where I have 174 individual git repos that I want to sync and run Simian and other static code analysis on to check for warnings/errors/duplicate code, etc.

 

I have even tried breaking the checkout down into multiple stages.  How do I fix this?  I have tried moving it out to a function but that does not work.  I have tried breaking down into multiple (12+) stages and also does not work.

My total script is 224 lines long (64K).  Not sure this should be too big.

jakub@pawlinski.pl (JIRA)

unread,
Sep 21, 2018, 11:45:12 AM9/21/18
to jenkinsc...@googlegroups.com

Getting same error while using much smaller pipeline, (actually it is delivered as shared library), whole thing (*.groovy) with comments and long property names has just slightly > 64kb. 

 

I guess when it is translated to one great method it is obfuscated / optimised.

 

Jesse Glick is there a way to monitor the size of transformed pipeline? Some output or custom job to monitor it would be great?

jglick@cloudbees.com (JIRA)

unread,
Sep 24, 2018, 5:17:03 PM9/24/18
to jenkinsc...@googlegroups.com

I do not foresee anyone spending much effort on this issue, as that would distract from the goal of moving Pipeline execution out of process, rendering this moot.

jakub@pawlinski.pl (JIRA)

unread,
Oct 1, 2018, 5:46:04 AM10/1/18
to jenkinsc...@googlegroups.com

Could you share some details on "moving Pipeline execution out of process", like is this on roadmap somewhere?

I don't need rendering, would be enough to output pipeline size during the build so I know how far I am from hitting this. Something like this:

   println Jenkins.instance.getPipelineSize('pipeline.groovy').toString()

 

dantran@gmail.com (JIRA)

unread,
Oct 14, 2018, 12:55:02 PM10/14/18
to jenkinsc...@googlegroups.com

svanoort@cloudbees.com (JIRA)

unread,
Oct 16, 2018, 11:41:03 AM10/16/18
to jenkinsc...@googlegroups.com

Jakub Pawlinski It is on the roadmap and has a couple engineers working hard on it (myself included), although we're not quite ready to demo or announce something (a few more pieces need to fall into place).

sergey.avseyev@gmail.com (JIRA)

unread,
Nov 12, 2018, 8:40:02 AM11/12/18
to jenkinsc...@googlegroups.com

jglick@cloudbees.com (JIRA)

unread,
Nov 13, 2018, 8:55:03 AM11/13/18
to jenkinsc...@googlegroups.com

sergey.avseyev@gmail.com (JIRA)

unread,
Nov 13, 2018, 9:25:02 AM11/13/18
to jenkinsc...@googlegroups.com

Jesse Glick, but last comment a month ago was about working hard on it. So I thought there might be some progress, or at least assignee for the issue.

jglick@cloudbees.com (JIRA)

unread,
Nov 13, 2018, 9:42:03 AM11/13/18
to jenkinsc...@googlegroups.com

No, the last comment was about working on a completely different execution engine that would not suffer from this class of bugs by design.

naval_gupta01@infosys.com (JIRA)

unread,
Dec 6, 2018, 1:03:22 AM12/6/18
to jenkinsc...@googlegroups.com

Any update or resolution on this issue.

Our production deployment is stuck due to this pipeline size restriction. 

Pipeline scripts fails in case it contains more than 78 build job statements in total. Right now, we are splitting the complete script into smaller pipeline scripts and then running all in predefined sequence, provided a single parallel cannot contain  more than 78 builds, currently

But its production and due to increase in server list, this count will go beyond 100 or more at some point of time and hence this pipeline job concept wont be of any use.

Therefore requesting you to expedite on this and provide us the update.

peter.thomson@ge.com (JIRA)

unread,
Jan 15, 2019, 2:36:02 AM1/15/19
to jenkinsc...@googlegroups.com

jpatel@everydayhealthgroup.com (JIRA)

unread,
Feb 7, 2019, 12:48:08 PM2/7/19
to jenkinsc...@googlegroups.com

We are on Jenkins 2.150.2 and Groovy Plugin 2.60.  We started getting this error when we upgraded Groovy to 2.6.1.  Our pipeline is about 690 lines.  It is a workflow to deploy 2 application components to staging servers and then to prod servers.  Please let us know when we can update get an update on this.

jpatel@everydayhealthgroup.com (JIRA)

unread,
Feb 7, 2019, 12:50:03 PM2/7/19
to jenkinsc...@googlegroups.com
J P edited a comment on Bug JENKINS-37984

henryborchers@yahoo.com (JIRA)

unread,
Feb 13, 2019, 11:31:09 AM2/13/19
to jenkinsc...@googlegroups.com

I'm running into this more and more. I've put what makes sense into shared libraries and squeeze more and more into ugly "helper functions" outside of the pipeline but it's getting really hard.

 

I really hope there is a better solution coming soon because I'm pretty sure that my coworkers are working with HR to have a talk with me about how much swearing I've been doing.

wim.gaethofs@gmail.com (JIRA)

unread,
Feb 19, 2019, 11:52:44 AM2/19/19
to jenkinsc...@googlegroups.com

Even when putting everything into shared libraries, my pipeline code is still 700+ lines. 

I had to split my code up into 2 jenkins jobs because of this issue. 

wim.gaethofs@gmail.com (JIRA)

unread,
Feb 19, 2019, 11:53:05 AM2/19/19
to jenkinsc...@googlegroups.com

henryborchers@yahoo.com (JIRA)

unread,
Feb 26, 2019, 11:20:03 AM2/26/19
to jenkinsc...@googlegroups.com

Sam Van Oort, it's been a few months since you teased us about something on your roadmap that would alleviate this issue. Any chance you could provide a little more info or at least tease us enough to wet our appetite? I'm running against the limit way too often these days. 

jglick@cloudbees.com (JIRA)

unread,
Mar 1, 2019, 6:16:03 PM3/1/19
to jenkinsc...@googlegroups.com

I am not aware of any plans to work on this issue. I tend to doubt it is fixable in the current Pipeline execution engine (workflow-cps), beyond better reporting the error. The known workaround is to split long blocks of code into distinct methods.

henryborchers@yahoo.com (JIRA)

unread,
Mar 4, 2019, 11:06:03 AM3/4/19
to jenkinsc...@googlegroups.com

Jesse Glick, a few post ago you mentioned something about creating a different execution engine that wouldn't have this issue. Anything you can point me to so that I can follow the progress or, at least, is anything interesting that you can tease to keep me hopeful that the future looks bright?

I have been putting any "steps block" that is more than 1 line into into helper functions but I'm still running into issues. 

I'm sorry if I come off as nagging. I just really love Jenkins. The declarative pipeline has been my one of favorite tools which I used for everything I build, 

jglick@cloudbees.com (JIRA)

unread,
Mar 4, 2019, 11:19:02 AM3/4/19
to jenkinsc...@googlegroups.com

Henry Borchers I believe that work is now inactive. I am afraid I have no particular advice for now beyond:

  • If at all possible, remove logic from Pipeline Groovy code and move it into external processes. We see a lot of people with these very complex calculations that could better have been done in some Python script or whatever in the workspace, so that the Pipeline part would boil down to just node {sh './something'}.
  • When not possible (for example because the Pipeline script is actually required to determine how to configure steps such as parallel or Jenkins publishers), split up long functions (including the implicit main function at top level of a Jenkinsfile) into shorter functions.

llibicpep@gmail.com (JIRA)

unread,
Mar 4, 2019, 12:27:03 PM3/4/19
to jenkinsc...@googlegroups.com

Any `Jenkinsfile` of any complexity can be shortened to just one line that looks like `doStuff()`. Does it makes sense to do it that way? Probably not but hopefully gives an idea as to where to move with this issue.

llibicpep@gmail.com (JIRA)

unread,
Mar 4, 2019, 12:29:03 PM3/4/19
to jenkinsc...@googlegroups.com

Let me re-phrase and sum-up some of the questions in that thread:

I'm writing off my application and even though I moved bunch of the stuff into separate methods I still keep all of my high-level app working flow in my `main()` method and it is still to big and java complains about that. Can you fix it plz?

llibicpep@gmail.com (JIRA)

unread,
Mar 4, 2019, 12:30:03 PM3/4/19
to jenkinsc...@googlegroups.com
Dmytro Kryvenko edited a comment on Bug JENKINS-37984
Let me re-phrase and sum-up some of the questions in that thread:

{quote}I'm writing off my application and even though I moved bunch of the stuff into separate methods I still keep all of my high-level app working flow in my `main()` method and it is still to big and java complains about that. Can you fix it plz?{quote}

I think the ticket may now be closed.

sergey.avseyev@gmail.com (JIRA)

unread,
Mar 4, 2019, 1:27:03 PM3/4/19
to jenkinsc...@googlegroups.com

Why you are talking about moving stuff into functions, and mention flows? This problem also reproducing in declarative pipelines, which do not have code at all. They just describes steps and each one is single-line and invokes built-in function.

llibicpep@gmail.com (JIRA)

unread,
Mar 4, 2019, 1:37:02 PM3/4/19
to jenkinsc...@googlegroups.com

Well if a declarative pipeline is so big that it won't fit into the limit - clearly the definition of a step needs some re-thinking. Sounds like a layer of abstraction required to wrap a multiple commonly-reusable steps into one to reduce the amount.

sergey.avseyev@gmail.com (JIRA)

unread,
Mar 4, 2019, 1:46:04 PM3/4/19
to jenkinsc...@googlegroups.com

are you saying that all steps I'm using in my pipeline also counted and inlined into result class object? stuff like zip(...), archiveartifacts, etc.?

llibicpep@gmail.com (JIRA)

unread,
Mar 4, 2019, 1:54:03 PM3/4/19
to jenkinsc...@googlegroups.com

Entire Jenkinsfile effectively becomes a body to some sort of `eval` function under the hood (for the sake of simplification let's forget about CPS and stuff). It's no difference if you split the code into the methods and still keep the methods in Jenkinsfile. Methods needs to be moved into shared library or otherwise made available in the Jenkinsfile scope.
No matter declarative or scripted pipeline - it's just directives that are effectively a Groovy closures. Standard java rules still applies no matter what.

jglick@cloudbees.com (JIRA)

unread,
Mar 4, 2019, 2:50:05 PM3/4/19
to jenkinsc...@googlegroups.com

This problem also reproducing in declarative pipelines

If true then it may be feasible to provide a fix in the pipeline-model-definition plugin, even without a general fix for Scripted.

eplotkin@drivenets.com (JIRA)

unread,
Mar 5, 2019, 1:42:03 AM3/5/19
to jenkinsc...@googlegroups.com
efo plo commented on Bug JENKINS-37984

We get this error in a purely declarative pipeline just by the sheer amount of 

stage {  when { ... } 
    agent { ... } 
    steps { ... } 
    post { success { ... } failure { ... } cleanup { ... } }
}

Add parallels, rinse, repeat — Method code too large.

Our steps {} are already a call to a single function.

This would be great if we could produce the stages in a separate function or file, but so far we can't find anything with regards to how to possibly go about it.

wim.gaethofs@gmail.com (JIRA)

unread,
Mar 5, 2019, 4:23:04 AM3/5/19
to jenkinsc...@googlegroups.com

I'm seeing the same thing as 'efo plo' in declarative pipeline.  Only defining the flow in the pipeline with stages, and calling shared libraries and functions to execute code. 

I now have 41 stages inside my pipeline{}. Adding just one more stage gives me this error. 

jglick@cloudbees.com (JIRA)

unread,
Mar 5, 2019, 8:36:03 AM3/5/19
to jenkinsc...@googlegroups.com

It would be helpful if someone observing this issue in Declarative could create a new issue in the pipeline-model-definition-plugin component (Link ed to this one) attaching a minimal, self-contained Jenkinsfile reproducing the error in a specified version of Jenkins and the workflow-cps (Pipeline: Groovy) and pipeline-model-definition (Pipeline: Declarative) plugins. I am not making any promises but that would at least improve the odds of a targeted fix for that case. (Bonus points for a pull request to jenkinsci/pipeline-model-definition-plugin adding an @Ignore d test case demonstrating the error.)

gilles.kacki@autoform.com (JIRA)

unread,
Mar 6, 2019, 3:39:03 AM3/6/19
to jenkinsc...@googlegroups.com
kgiloo commented on Bug JENKINS-37984

you can only move your code at the script level in classes but you can't do this at the stage(s) level, which restricts drastically any refactoring.

i have a parallel job running on 6 different platforms, "same" stages, but i have to copy-paste stages in a monster pipeline, which ends up into a 1130 lines call method.

this is really a deal breaker in pure declarative.

llibicpep@gmail.com (JIRA)

unread,
Mar 7, 2019, 9:09:11 AM3/7/19
to jenkinsc...@googlegroups.com

you can only move your code at the script level in classes but you can't do this at the stage(s) level, which restricts drastically any refactoring.

That's not entirely true. What I'm going to say might be too advance level for many users, but pipelines that hitting this limit to me sounds pretty advance. Shared library can provide your own custom declarative syntax (or imperative if you prefer). Shared library then, being a layer of abstraction, can calculate resulting Jenkinsfile (either declarative or scripted) based on your input and send it to `eval()`.

gilles.katski@autoform.com (JIRA)

unread,
Mar 7, 2019, 9:29:14 AM3/7/19
to jenkinsc...@googlegroups.com
kgiloo commented on Bug JENKINS-37984

Dmytro Kryvenko i am afraid i do not get your point.

scope is pure declarative. hence, i doubt you can wrap any code but inside script { } out of your main pipeline.

if you can do so, then please post a snippet of code, thank you.

eplotkin@drivenets.com (JIRA)

unread,
Mar 7, 2019, 9:34:03 AM3/7/19
to jenkinsc...@googlegroups.com

eplotkin@drivenets.com (JIRA)

unread,
Mar 7, 2019, 9:35:12 AM3/7/19
to jenkinsc...@googlegroups.com
efo plo commented on Bug JENKINS-37984
 
Re: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during class generation: Method code too large! error in pipeline Script

Added a sample Jenkinsfile reproducing the problem.
It is also available at https://pastebin.com/eDVppFjm

```org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:


General error during class generation: Method code too large!

java.lang.RuntimeException: Method code too large!
at groovyjarjarasm.asm.MethodWriter.a(Unknown Source)
at groovyjarjarasm.asm.ClassWriter.toByteArray(Unknown Source)
```

Any and all ideas with regards to how this may be refactored are more than welcome.

eplotkin@drivenets.com (JIRA)

unread,
Mar 7, 2019, 9:35:14 AM3/7/19
to jenkinsc...@googlegroups.com
efo plo edited a comment on Bug JENKINS-37984

eplotkin@drivenets.com (JIRA)

unread,
Mar 7, 2019, 9:36:04 AM3/7/19
to jenkinsc...@googlegroups.com
efo plo edited a comment on Bug JENKINS-37984
Added a sample Jenkinsfile reproducing the problem.
It is also available at https://pastebin.com/eDVppFjm

``` {code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during class generation: Method code too large!

java.lang.RuntimeException: Method code too large!
at groovyjarjarasm.asm.MethodWriter.a(Unknown Source)
at groovyjarjarasm.asm.ClassWriter.toByteArray(Unknown Source)
``` {code}

Any and all ideas with regards to how this may be refactored are more than welcome.

llibicpep@gmail.com (JIRA)

unread,
Mar 7, 2019, 9:44:11 AM3/7/19
to jenkinsc...@googlegroups.com

The very basic example is all there https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-declarative-pipelines. You don't define parts of the pipeline but entire pipeline inside of the library. Example is pretty primitive, my idea is that the library can implement a number of custom closures to make available a following syntax:

{{myPipeline("platform")

{ foo "bar" deploy "baz }

}}

In other words making the input Jenkinsfile nothing more than a metadata file explaining what's inside of this repository. Shared library in turn can do calculations based on input above and pretty much do a lot of templating work in order to produce real Jenkinsfile to sent it to `eval()` or execute inline.

Another example https://jenkins.io/blog/2017/10/02/pipeline-templates-with-shared-libraries/

llibicpep@gmail.com (JIRA)

unread,
Mar 7, 2019, 9:45:19 AM3/7/19
to jenkinsc...@googlegroups.com
Dmytro Kryvenko edited a comment on Bug JENKINS-37984
The very basic example is all there [ https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-declarative-pipelines ] . You don't define parts of the pipeline but entire pipeline inside of the library. Example is pretty primitive, my idea is that the library can implement a number of custom closures to make available a following syntax:

{ { code:java}
myPipeline("platform") {
    foo "bar"
 
  deploy "baz
}
{code } }

In other words making the input Jenkinsfile nothing more than a metadata file explaining what's inside of this repository. Shared library in turn can do calculations based on input above and pretty much do a lot of templating work in order to produce real Jenkinsfile to sent it to `eval()` or execute inline.

Another example
[ https://jenkins.io/blog/2017/10/02/pipeline-templates-with-shared-libraries/ ]

llibicpep@gmail.com (JIRA)

unread,
Mar 7, 2019, 9:45:29 AM3/7/19
to jenkinsc...@googlegroups.com

eplotkin@drivenets.com (JIRA)

unread,
Mar 7, 2019, 9:53:02 AM3/7/19
to jenkinsc...@googlegroups.com
efo plo commented on Bug JENKINS-37984

In my understanding, that would do nothing except moving the error to the stage of compiling the shared library method defining this pipeline. But if you could attach a pastebin that would compile that pipeline, I'd be more than happy to be proven wrong. Please note that while I simply replicated the same stage over and over, in our practice every stage is calling different functions (all of which are already defined in a shared library).

eplotkin@drivenets.com (JIRA)

unread,
Mar 7, 2019, 9:54:14 AM3/7/19
to jenkinsc...@googlegroups.com

llibicpep@gmail.com (JIRA)

unread,
Mar 7, 2019, 9:57:03 AM3/7/19
to jenkinsc...@googlegroups.com

Well, if you do something like this but resulting Jenkinsfile produced is still in declarative style, you probably don't solve anything as the size of it will still be huge. But the point is - you just came up with your own declarative style that is simpler, smaller, and better suits your project or organization as being designed specifically for it. So you probably don't need declarative style being produced any more as it becomes nothing more than an intermediate format between the shared library and Jenkins (sort of JIT in Java world, really just a language that machine talking to a machine). There's no point in all that declarative style limits. In turn, if produced result is in scripted format - can be split into chunks and eval() separately, for instance per stage.

I guess my point is - declarative style just sucks. From my experience it works only for small and simple projects despite how hard it's being advertised an opposite.

eplotkin@drivenets.com (JIRA)

unread,
Mar 7, 2019, 10:09:14 AM3/7/19
to jenkinsc...@googlegroups.com
efo plo commented on Bug JENKINS-37984

As it is, I am not looking to come up with my own declarative style or a specific custom-fit design for my organization. I am just trying to do my job fighting this "Method code too large!" error.

llibicpep@gmail.com (JIRA)

unread,
Mar 7, 2019, 10:26:03 AM3/7/19
to jenkinsc...@googlegroups.com

eplotkin@drivenets.com (JIRA)

unread,
Mar 7, 2019, 10:47:13 AM3/7/19
to jenkinsc...@googlegroups.com

henryborchers@yahoo.com (JIRA)

unread,
Mar 8, 2019, 11:36:03 AM3/8/19
to jenkinsc...@googlegroups.com

Well then you may be trying to apply a wrong tool for the job. Try some commercial offers maybe.

I understand your be frustrated but comments like this are not very helpful.

I guess my point is - declarative style just sucks. From my experience it works only for small and simple projects despite how hard it's being advertised an opposite.

I couldn't disagree more.  It's super easy to read and understand. It has a clean syntax. It's well thought out. It's expandable with scripts if need be. It's so easy to to look through the blue ocean to see why something has failed. It's freaking brilliant!!!

 

The declarative pipeline is the main reason that I use Jenkins and why I advocate for it wherever I go.  Did I mention it's brilliant? The biggest issue is that it is so easy to use, that I just want to use it more and more until I get smacked in the face with "Method code too large!.  It's a little bit like the use of electricity over the last century. Most electronic devices have become more efficient throughout the decades and use less electricity as their designs have improved. However, we keep finding new uses for electricity at a faster rate than we can make them more efficient.  We end up needing more and more power plants as a result, not fewer.

I feel the same way with Jenkins and especially the declarative pipeline. I've been getting the lines in my steps into fewer and fewer lines. I make shared-libraries for my common code and "helper script functions" outside of the pipeline block. However, I keep finding more and more ways to find problems in my code early with careful placement of "sequential and parallel stages" and "when and post" blocks.  I end up with lots of stages with one or two lines in the steps block. Then all of a sudden, I run into "Method code too large!"... And then I become a sad developer...

llibicpep@gmail.com (JIRA)

unread,
Mar 8, 2019, 11:48:16 AM3/8/19
to jenkinsc...@googlegroups.com

I understand your be frustrated but comments like this are not very helpful.

Well sometimes truth is not helpful at all. What's your point? Maybe you have a solution or even a PR? Enlighten us.

I couldn't disagree more.

You didn't seem to read my suggestion careful enough. Declarative approach, indeed, is the future. Particular Jenkinsfile declarative implementation sucks, though. Because you kind of use declarative style but you still have to imperatively define steps. What a bummer!

If you read careful enough what I said, you'll see what I opted in for is rather to have a small meta data file in the repository that explains facts about the app inside, so that the library can deal with it and render a pipeline for it. This render body is much easier to work with when it's scripted style, and the fact that it's scripted doesn't matter because users don't directly deal with it.

ashsy009@gmail.com (JIRA)

unread,
Jun 19, 2019, 11:31:03 AM6/19/19
to jenkinsc...@googlegroups.com
Ashwin Y commented on Bug JENKINS-37984

hello,
Is there any solution or workaround for this?
This is open from last 3 months !! Please provide some solution to this......

baisani.sivanarayana@gmail.com (JIRA)

unread,
Jun 19, 2019, 4:15:07 PM6/19/19
to jenkinsc...@googlegroups.com

I have a strange scenario with this error. So I have jobs which are huge in size the 1st job is about 1200 lines long and it works completely fine and the 2nd job is about 850 lines and it got this error. 

baisani.sivanarayana@gmail.com (JIRA)

unread,
Jun 19, 2019, 4:16:03 PM6/19/19
to jenkinsc...@googlegroups.com
I have a strange scenario with this error. So I have jobs which are huge in size the 1st job is about 1200 lines long and it works completely fine and the 2nd job is about 850 lines and it got this error.   And by removing some lines from the code worked fine.

baisani.sivanarayana@gmail.com (JIRA)

unread,
Jun 19, 2019, 4:17:04 PM6/19/19
to jenkinsc...@googlegroups.com

baisani.sivanarayana@gmail.com (JIRA)

unread,
Jun 19, 2019, 4:23:13 PM6/19/19
to jenkinsc...@googlegroups.com
I have a strange scenario with this error. So I have jobs which are huge in size the 1st job is about 1200 lines long and it works completely fine and the 2nd job is about 850 lines and it got this error. And by removing some lines from the code worked fine. I added the same code again adding stage by stage and it worked fine again. It's the same code, same number of lines nothing changed but different behaviors.

baisani.sivanarayana@gmail.com (JIRA)

unread,
Jun 19, 2019, 8:37:03 PM6/19/19
to jenkinsc...@googlegroups.com

jbennett2091@yahoo.com (JIRA)

unread,
Jun 27, 2019, 6:20:03 PM6/27/19
to jenkinsc...@googlegroups.com

There is a work around, of sorts.  There is a fixed limit to the size of the groovy.  No way around that limit, but you can do things to minimize what's in groovy.

Eliminate clutter.   For us, that was stuff like echo statements, and unused variables.  You might also be able to alter the jenkins job's configuration rather than setting options in the groovy.

 

A better answer is to shift large blocks to scripts.  For example, if you have a bunch of "sh" or "bat" commands in a row, put them in a script file, then invoke the script from groovy. 

 

Good luck.  This limit should still be fixed (or raised).  You just cannot get to enterprise worthy pipelines with it.

 

spinus1@gmail.com (JIRA)

unread,
Jul 12, 2019, 4:42:03 AM7/12/19
to jenkinsc...@googlegroups.com

Hello,

this is causing troubles also on my company...I think that a solution could be moving bash commands to an external file or using groovy libraries, but during initial development phase of pipeline I usually put all the code in the a single file: it is not maintainable, but it is what I need to quickly develop and test new pipelines.

I'll be really grateful to Jenkins developers if they can solve this issue

BR,

Alessio

spinus1@gmail.com (JIRA)

unread,
Aug 9, 2019, 4:37:10 AM8/9/19
to jenkinsc...@googlegroups.com

Hello,

I'm just fiddling with groovy shared libraries, it helped me reducing code size a  bit, but now I'm pretty stuck since I cannot reduce it anymore, so each line I add is causing the issue...maybe I'm not using shared libraries in the correct way? Does anyone have some hints on this?

 

BR,

Alessio

mueck.carsten@web.de (JIRA)

unread,
Aug 14, 2019, 9:30:04 AM8/14/19
to jenkinsc...@googlegroups.com

Workaround:
Move your code into different scripts inside an extra Jenkinsfile Repository (or in your Build-Repository), check those files out, load them into variables and call the code as function.
Example
Jenkinsfile (Main executed)

node(){
    checkout Jenkinsfile-repo
    def HelperScript = load("path/to/helperscript.groovy")
    Helperscript.DoYourWork()
}

helperscript.groovy

#!groovy
def DoYourWork(){
     //Do something that doesn't work because too much to load in initial script
}
//Important statement for loading the script!!!
return this

As the script is not loaded initially it can compile the main Jenkinsfile.

Hope that works for more people then just me

eplotkin@drivenets.com (JIRA)

unread,
Aug 14, 2019, 11:13:03 AM8/14/19
to jenkinsc...@googlegroups.com
efo plo commented on Bug JENKINS-37984

Carsten Mück If one can't define a pipeline inside `DoYourWork()` function — which I suspect is not the case, though I haven't tried it — this does not solve the original issue.

It is loading more messages.
0 new messages