我发现了如何从这个SO answer动态创建输入参数
agent any
stages {
stage("Release scope") {
steps {
script {
// This list is going to come from a file, and is going to be big.
// for example purpose, I am creating a file with 3 items in it.
sh "echo \"first\nsecond\nthird\" > ${WORKSPACE}/list"
// Load the list into a variable
env.LIST = readFile (file: "${WORKSPACE}/list")
// Show the select input
env.RELEASE_SCOPE = input message: 'User input required', ok: 'Release!',
parameters: [choice(name: 'CHOOSE_RELEASE', choices: env.LIST, description: 'What are the choices?')]
}
echo "Release scope selected: ${env.RELEASE_SCOPE}"
}
}
}
}
这允许我们只选择一个,因为它是choice
参数,如何使用同一列表创建复选框参数,以便用户可以根据需要选择多个参数?例如:如果用户选择first
和third
,那么最后一个echo应该输出Release scope selected: first,third
,或者下面的代码也可以,因此我可以迭代并找到 true 的Release scope selected: {first: true, second: false, third: true}
2条答案
按热度按时间xxe27gdn1#
我可以使用
extendedChoice
,如下所示n9vozmp42#
有一个
booleanParam
:https://www.jenkins.io/doc/book/pipeline/syntax/#parameters它的名字很奇怪,因为所有其他的param类型都没有“Param”这个名字。
string
、choice
等等。