如何有条件地隐藏参数?
How to conditionally hide parameter?
我正在尝试创建一个带参数的 jenkins 管道作业。我希望参数有条件地显示。条件取决于先前参数的选择。
我试过Active choices插件。它允许我有条件地选择参数值。我希望整个参数有条件地出现在 UI 中。
jenkins 管道文件是否可行?
我不相信这是可能的。在 declarative/scripted 管道的情况下,参数是 'post-processed',这意味着您看到的本质上是在之前的 'run/build' 中评估的内容。这就是为什么它需要在 'Build with Parameters' 可用之前构建。
作为替代方案,(如果您使用 scripted/declarative 管道)您可以使用输入步骤并使其有条件地触发。
if ( x == true ) {
def userInput = input(
id: 'userInput', message: 'Let\'s promote?', parameters: [
[$class: 'TextParameterDefinition', defaultValue: 'uat', description: 'Environment', name: 'env'],
[$class: 'TextParameterDefinition', defaultValue: 'uat1', description: 'Target', name: 'target']
])
}
示例来自:
https://support.cloudbees.com/hc/en-us/articles/204986450-Pipeline-How-to-manage-user-inputs
我正在尝试创建一个带参数的 jenkins 管道作业。我希望参数有条件地显示。条件取决于先前参数的选择。
我试过Active choices插件。它允许我有条件地选择参数值。我希望整个参数有条件地出现在 UI 中。
jenkins 管道文件是否可行?
我不相信这是可能的。在 declarative/scripted 管道的情况下,参数是 'post-processed',这意味着您看到的本质上是在之前的 'run/build' 中评估的内容。这就是为什么它需要在 'Build with Parameters' 可用之前构建。
作为替代方案,(如果您使用 scripted/declarative 管道)您可以使用输入步骤并使其有条件地触发。
if ( x == true ) {
def userInput = input(
id: 'userInput', message: 'Let\'s promote?', parameters: [
[$class: 'TextParameterDefinition', defaultValue: 'uat', description: 'Environment', name: 'env'],
[$class: 'TextParameterDefinition', defaultValue: 'uat1', description: 'Target', name: 'target']
])
}
示例来自: https://support.cloudbees.com/hc/en-us/articles/204986450-Pipeline-How-to-manage-user-inputs