【发布时间】:2020-09-20 17:26:08
【问题描述】:
我发现了如何从这个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,那么最后一个回显应该打印
Release scope selected: first,third 或以下也可以,所以我可以遍历并找到 true 的 Release scope selected: {first: true, second: false, third: true}
【问题讨论】:
标签: jenkins groovy jenkins-pipeline pipeline jenkins-groovy