0

I have a jenkins job with multi select extended choice parameter. There are list of elements in a parameter. So, my requirement is I want to allow users to select multiple parameters excluding first element in a parameter. Means user should not able to select first element with other elements in a parameters. I am using jenkinsfile to create parameter.

enter image description here

Like shown above, users should not able to select 'None' with any other element in a parameter. Does anyone know how to do this?

svw1105
  • 127
  • 1
  • 15

1 Answers1

0

I don't think you can do this with just Extended choice parameter. As a workaround, you can add two parameters. The first parameter to check whether it's None or not, if not you can bring up the second parameter. You can use the Active Choice Parameter for this.

properties([
    parameters([
        [$class: 'CascadeChoiceParameter', 
            choiceType: 'PT_MULTI_SELECT',
            description: 'Select a choice',
            filterLength: 1,
            name: 'choice1',
            referencedParameters: 'CHOICE',
            script: [$class: 'GroovyScript',
                fallbackScript: [
                    classpath: [], 
                    sandbox: true, 
                    script: 'return ["ERROR"]'
                ],
                script: [
                    classpath: [], 
                    sandbox: true, 
                    script: """
                        if (CHOICE == 'Yes') { 
                            return['Item1','Item2','Item3']
                        }
                        else {
                            return[]
                        }
                    """.stripIndent()
                ]
            ]
        ]
    ])
])

pipeline {
    agent any
    parameters {
        choice(name: 'CHOICE', description: "Do you have any choices?", choices: ["Yes", "None"])
    }
    stages {
        stage("Run Tests") {
            steps {
                sh "echo SUCCESS on ${params.CHOICE}"
            }
        }
    }
}
ycr
  • 12,828
  • 2
  • 25
  • 45
  • Actually, there will be multiple parameters and I want to allow user to select multiple parameters at once except None – svw1105 Sep 21 '22 at 10:29
  • @svw1105 I think you didn't get my point. Check the updated answer with a working Pipeline. – ycr Sep 21 '22 at 12:40