In a Jenkins pipeline, it is possible to request input data using
def returnValue = input message: 'Need some input',
parameters: [string(defaultValue: 'adefval', description: 'a', name: 'aaa'),
string(defaultValue: 'bdefval', description: 'b', name: 'bbb')]
To build such a list dynamically, I tried something like
def list = ["foo","bar"]
def inputRequest = list.collect { string(defaultValue: "def", description: 'description', name: it) }
def returnValue = input message: 'Need some input', parameters: [inputRequest]
This does not work:
java.lang.ClassCastException: class org.jenkinsci.plugins.workflow.support.steps.input.InputStep.setParameters() expects class hudson.model.ParameterDefinition but received class java.util.ArrayList
Probably, Groovy can figure out dynamically in the first case which object is required, but in the second case it does not work anymore, as collect returns an ArrayList?
How to create such a list correctly?
edit: maybe this question not very useful for itself, but may still serve as a code sample...