尝试在事件选择参数“脚本”部分调用定义的函数似乎不起作用:
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
}
尝试使用参数构建时收到错误
附注'input' 不适合我,我需要在开始之前选择参数
最佳答案
在没有看到错误的情况下,我认为这只是确保您向 choices 参数提供正确数据类型(字符串)的问题。
对于 List 的返回类型,将它们与换行符连接在一起,如下所示。如果是其他东西,您将需要进一步操作它
List JustTest() {
List xxx = ['a','b']
return xxx
}
properties([
parameters([
choice(name: 'PARAM', choices: JustTest().join('\n'), description: 'Choice'),
])
])
我认为不需要如此冗长的选择实现,但也许我们的 jenkins 插件存在差异。或许可以试试我的较短的那个,而不用 $class 冗长。
关于jenkins-pipeline - 使用 Groovy 脚本的 Jenkins Active Choice 参数调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56998355/