Reputation: 431
Trying to call a defined function in active choice parameter 'script' part seems doesn't work:
def JustTest() {
xxx = ['a','b']
return xxx
}
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
////
some code omitted
////
script: [
classpath: [], sandbox: false,
script:
"""
def mymy = JustTest()
return mymy
"""
]
]
]
])
])
pipeline {
some code
}
when trying to build with parameters an error is received
p.s. 'input' doesn't fit for me, I need to choose parameters before starting
Upvotes: 3
Views: 10576
Reputation: 2882
Without seeing the error, i think its just a matter of ensuring your supplying the correct datatype (string) to the choices param.
For a return type of List, join them together with newlines as show below. If its something else you will need to manipulate it further
List JustTest() {
List xxx = ['a','b']
return xxx
}
properties([
parameters([
choice(name: 'PARAM', choices: JustTest().join('\n'), description: 'Choice'),
])
])
I dont think there is a need for such a verbose choice implementation, but perhaps there are differences in our jenkins plugins. Perhaps give my shorter one a try without all the $class verbosity.
Upvotes: 0