【问题标题】:How can I delete one property from Jenkins pipeline?如何从 Jenkins 管道中删除一个属性?
【发布时间】:2018-05-07 16:47:58
【问题描述】:

在我的 Jenkins 多分支管道中,我想在我的 Jenkinsfile 中使用以下代码:

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
}

但我如何才能仅在条件 1 为真的情况下删除属性 VALUE_NAME? 我只找到了 sintax:

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

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

【问题讨论】:

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


    【解决方案1】:

    我的解决方法:

    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)
    

    【讨论】:

    • 我认为你的意思是第一行的“def”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    • 1970-01-01
    • 2018-05-05
    相关资源
    最近更新 更多