red*_*888 18 jenkins jenkins-plugins jenkins-pipeline
很沮丧我找不到这个例子.如何设置默认选项?
parameters {
choice(
defaultValue: 'bbb',
name: 'param1',
choices: 'aaa\nbbb\nccc',
description: 'lkdsjflksjlsjdf'
)
}
Run Code Online (Sandbox Code Playgroud)
defaultValue在这里无效.我希望选择是可选的,并且如果管道是非手动运行(通过提交),则设置默认值.
mko*_*bit 29
您无法在选项中指定默认值.根据choice输入的文档,第一个选项将是默认选项.
潜在的选择,每行一个.第一行的值将是默认值.
return new StringParameterValue(
getName(),
defaultValue == null ? choices.get(0) : defaultValue, getDescription()
);
Run Code Online (Sandbox Code Playgroud)
正如 mkobit 所说,defaultValue参数似乎不可能,而是我根据上一个选择重新排序了选择列表
defaultChoices = ["foo", "bar", "baz"]
choices = createChoicesWithPreviousChoice(defaultChoices, "${params.CHOICE}")
properties([
parameters([
choice(name: "CHOICE", choices: choices.join("\n"))
])
])
node {
stage('stuff') {
sh("echo ${params.CHOICE}")
}
}
List createChoicesWithPreviousChoice(List defaultChoices, String previousChoice) {
if (previousChoice == null) {
return defaultChoices
}
choices = defaultChoices.minus(previousChoice)
choices.add(0, previousChoice)
return choices
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21989 次 |
| 最近记录: |