0

In my Jenkins multibranch pipeline I want to use the following code in my 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
}

But how can I remove the property VALUE_NAME only in case where condition1 is true? I found only the sintax:

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

^^ This removes all the parameters even if my variables don't have names with common body like in this example ("VALUE_NAME").
And with this sintax, once the build has run once, I am not able to see the "Build with paramtres" button on the job UI, but "Build now".

SimLine
  • 11
  • 8

1 Answers1

0

My workaround:

Script

def 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)
SimLine
  • 11
  • 8