<p>Try with tokenize (,) since the options were saved like a string.
Save 'NAMES' into a new variable, then tokenize with a comma &quot;,&quot; since it was configured the parameters with multiSelectDelimiter: ','
Finally, you can iterate the array with a for-loop and use the elements as desire.</p>
<pre class="lang-bash prettyprint-override"><code>  def arr = userInput['NAMES'].tokenize(',')

  arr.each { t -&gt;
    // t is the parameter option
    sh(&quot;echo ${t}&quot;)
  }
</code></pre>

CC BY-SA 4.0
2021-06-21T03:16:49.590Z
This might work and thank you for contributing, but a very good answer would say why and explain the code a bit
Peter Turner
CC BY-SA 4.0
2021-06-20T22:45:07.817Z
2021-06-21T13:15:08.250Z
2021-06-21T13:15:08.250Z
elulcao
<p>I have the following declarative pipeline. It defines checkbox multi-choice parameter:</p>

<pre><code>pipeline {
    agent any 
    options {
        ansiColor('xterm')                    
    }
    parameters { 
        extendedChoice description: '', multiSelectDelimiter: ',', name: 'NAMES', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', value:'a,b,c', visibleItemCount: 3
    } 
    stages {
      stage('Run on all') {

        steps { 
            script {
                  println params.NAMES 
            }
        }   
      }
    }

}
</code></pre>

<p>My goal is to call the pipeline via Jenkins CLI where passed values to <code>NAMES</code> parameter signifies selected checkboxes.</p>

<p>Running  <code>java -jar jenkins-cli.jar  -s http://localhost:8080 -auth u:p -p NAMES='a'</code> causes empty string to be printed by <code>println params.NAMES</code></p>

<p>Expected <code>a</code> to be printed after calling the pipeline via Jenkins cli client.</p>

<p>The only way that worked is adding commas after <code>a</code>: <code>java -jar jenkins-cli.jar  -s http://localhost:8080 -auth u:p -p NAMES='a,,'</code></p>

<p>Is it the correct syntax to pass checkbox selections of <code>extendedChoice</code> type parameter?</p>

<jenkins><jenkins-pipeline><jenkins-plugins>
Passing parameters of extendedChoice type to Jenkins Pipeline via jenkins-cli.jar
rokpoto.com
# Passing parameters of extendedChoice type to Jenkins Pipeline via jenkins-cli.jar

(Asked by: username_0 on 2020-06-10)

I have the following declarative pipeline. It defines checkbox multi-choice parameter:
pipeline {
    agent any 
    options {
        ansiColor('xterm')                    
    }
    parameters { 
        extendedChoice description: '', multiSelectDelimiter: ',', name: 'NAMES', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', value:'a,b,c', visibleItemCount: 3
    } 
    stages {
      stage('Run on all') {

        steps { 
            script {
                  println params.NAMES 
            }
        }   
      }
    }

}

My goal is to call the pipeline via Jenkins CLI where passed values to NAMES parameter signifies selected checkboxes.
Running  java -jar jenkins-cli.jar  -s http://localhost:8080 -auth u:p -p NAMES='a' causes empty string to be printed by println params.NAMES
Expected a to be printed after calling the pipeline via Jenkins cli client.
The only way that worked is adding commas after a: java -jar jenkins-cli.jar  -s http://localhost:8080 -auth u:p -p NAMES='a,,'
Is it the correct syntax to pass checkbox selections of extendedChoice type parameter?

**Tags:** jenkins, jenkins-pipeline, jenkins-plugins


---

## 1 answers

### Answer by username_1 on 2021-06-20. Score: 1

Try with tokenize (,) since the options were saved like a string.
Save 'NAMES' into a new variable, then tokenize with a comma "," since it was configured the parameters with multiSelectDelimiter: ','
Finally, you can iterate the array with a for-loop and use the elements as desire.
  def arr = userInput['NAMES'].tokenize(',')

  arr.each { t ->
    // t is the parameter option
    sh("echo ${t}")
  }

> **Comments:**
> **username_2**: This might work and thank you for contributing, but a very good answer would say why and explain the code a bit  

---

