如何从Jenkins管道中删除一个属性?

时间:2018-05-07 16:47:58

标签: jenkins jenkins-plugins jenkins-pipeline multibranch-pipeline

在我的Jenkins multibranch管道中,我想在Jenkins文件中使用以下代码:

def props = [
    parameters([
        string(
            defaultValue: "Value1",
            name: 'VALUE_NAME',
            description: 'Something'),
        string(
            defaultValue: "Value2",
            name: 'VALUE_NAME_v2',
            description: 'Something else')
])]
properties(props)

if(condition1) {
    // remove only VALUE_NAME
}

但是,如果condition1为true,我该如何删除属性VALUE_NAME? 我发现只有sintax:

props.removeAll { it.toString().contains('VALUE_NAME')}

^^这将删除所有参数,即使我的变量没有像这个例子中那样具有共同主体的名称(“VALUE_NAME”)。
使用这个sintax,一旦构建运行一次,我就无法在作业UI上看到“Build with paramtres”按钮,但是“立即构建”。

1 个答案:

答案 0 :(得分:0)

我的工作:

dep params = [
    string(
        defaultValue: "Value1",
        name: 'VALUE_NAME_v1',
        description: 'Something'),
    string(
        defaultValue: "Value2",
        name: 'VALUE_NAME_v2',
        description: 'Something else')
]
if(condition1) {
    // remove only VALUE_NAME_v1
    params.removeAll {it.toString().contains("VALUE_NAME_v1")}
}
def props = [
    parameters(params)]
properties(props)