目前,我正在使用 Active Choices 插件来配置我的管道。 我有 3 个不同的参数用于构建管道。
第二个参数更新为第一个参数选择的值。 第三个参数更新为第二个参数选择的值。
但是,我观察到,对于该特定版本号,第三个参数的值保持不变(无论第二个参数中选择的任何不同选项如何)。 第三个参数值(当前版本中)是第二个参数(上一个版本中)点击结果的值
例如: 在第二个参数中,我选择branch2。 IFF 我在之前的构建中为第二个参数选择了branch2,它会显示值:model3、model4。 IFF NOT,然后是其他一些值。
在图像中,尽管单击了branch1,它仍然显示上次运行的parameter3中的值
我的代码:
properties([
parameters([
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
name: 'RUN_TESTS',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script: 'return ["ERROR"]'
],
script: [
classpath: [],
sandbox: true,
script:"""
return ["YES","NO"]
"""
]
]],
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_RADIO' ,
name: 'BRANCH',
referencedParameters: 'RUN_TESTS',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script: 'return ["ERROR"]'
],
script: [
classpath: [],
sandbox: true,
script:"""
if(RUN_TESTS.equals("YES")){
return ["${getDummyBranches().join('","')}"]
}else{
return ["Disabled: Select 'Yes' to enable"]
}
"""
]
]] ,
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_CHECKBOX',
//choiceType: 'PT_RADIO' ,
name: 'MODEL_INFO',
description: 'Select the test model to build?',
referencedParameters: 'BRANCH',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: true,
script: 'return ["ERROR"]'
],
script: [
classpath: [],
sandbox: true,
script:"""
if(BRANCH!=null && !BRANCH.isEmpty() && !BRANCH.contains("Disabled:")){
return ["${getDummyModels(BRANCH).join('","')}"]
}else{
return ["Disabled: Select the appropriate branch above"]
}
""" ]
]]
])
])
def getDummyBranches() {
return ["branch1", "branch2", "branch3"]
}
def getDummyModels(valu) {
if (valu.equals("branch1")) {
println("inside the branch1 condition")
return ["model1", "model2"]
} else if (valu.equals("branch2")) {
println("inside the branch2 condition")
return ["model3", "model4"]
} else {
return ["model5", "model6"]
}
}
node {
stage('Print Parameters') {
println "xxx"
}
}
Jenkins版本:2.447 主动选择:2.8.3
如何立即实现第三个参数的动态行为? 非常感谢建议/想法
您的
getDummyBranches()
和 getDummyModels(valu)
方法称为 during 作业执行,它们有助于在作业定义中设置参数。这些参数将在下次执行时使用,单击 Configure
菜单即可看到它们。用户与参数的交互发生在作业执行之前,实际上是在从 scm 检索作业之前,因此您定义的方法在该阶段不可用。主动选择参数的 Groovy 脚本必须是自包含的,它们不能调用管道或共享库中的方法。