Search code examples
jenkinsgroovyjenkins-pipeline

Jenkins pipeline map is getting converted to an array but it's too large I think?


I'm trying to make an addition to a gigantic properties map (no, refactoring isn't an option to correct my team's terrible decisions) initialising function.

The flow is essentially the same as this simplified example:

file1.groovy has:

def call(Map opts = [:]) {
    opts = file2(opts)
    // do some stuff with the opts...
}

Where file2.groovy has an obnoxious number of options defaulting statements like this:

def call(Map opts = [:]) {
    opts.something = opts.something ?: true
    opts.something2 = opts.something ?: false
}

I'm trying to add a couple of options to this on a run I'm getting an error of:

org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 6e0ca570-b8b5-4c4b-93bb-e3d5661c1294
java.lang.NoSuchMethodError: 'java.lang.Object[] org.codehaus.groovy.runtime.ArrayUtil.createArray(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object,

Where the "java.lang.Object," just goes on for like 20 lines.

I've done some looking and apparently there is a limit to the createArray function of 250 objects.

However, my main question is how (under the hood, I'm assuming) is createArray getting called in the flow described? Is the map getting transformed in to an array to be passed between the functions, is it something to do with CPS?

Assuming a re-design of this terrible system isn't possible, is there a way around this issue?

I need to add 5 more items to the map, if I comment out 2 of them, it works fine.


Solution

  • You are right, it is related to CPS and adding @NonCPS solves it.

    @NonCPS
    def call(Map opts = [:]) {
        opts.something = opts.something ?: true
        opts.something2 = opts.something ?: false
    }