'How to use choice() method in groovy?

Sorry for the noob question. I'm new to Groovy.

I'm debugging some Jenkins scripts with the groovysh utility. Here is a snippet of code:

println("Start")

List job_params() {
    def parameter_list = [
            choice(name: 'BAUDRATE',
                choices: ['9600', '115200'],
                description: 'Baud rate of the device.'),
        ]

    return parameters(parameter_list)
}

params = job_params()

println("End")

When I try to run this code I receive error message:

groovy:000> :load BExample.gvy
Start
===> null
===> true
ERROR groovy.lang.MissingMethodException:
No signature of method: groovysh_evaluate.choice() is applicable for argument types: (java.util.LinkedHashMap) values: [[name:BAUDRATE, choices:[9600, 115200], description:Baud rate of the device.]]
Possible solutions: collect()
        at groovysh_evaluate.job_params (groovysh_evaluate:6)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)

Do I need to "import" something? How can I fix this problem.

BTW, this code snippet works on Jenkins without error.



Solution 1:[1]

As I mentioned above under comments, you may like to refer to https://github.com/jenkinsci/job-dsl-plugin/blob/master/docs/User-Power-Moves.md to run your DSL locally.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hitesh A. Bosamiya