Home > other >  Loop through multi selection value of Jekins Parameter BooleanParam
Loop through multi selection value of Jekins Parameter BooleanParam

Time:08-08

I have on-premise Jenkins node slave that are running. The value of each param is the nodename. For example the nodename I have is (value1,value2,value3) Suppose a user select a value1 and value2 in the parameter options in the checkbox, I want to be able to loop the selected params and pass the value to the node($selected).

That means Jenkins will connect to value1 and value2 node. Any Idea how to do this?

The code is here:

#!/usr/bin/env groovy


properties([
    parameters([

booleanParam(name: 'value1', defaultValue: false, description: '') ,
booleanParam(name: 'value2', defaultValue: false, description: '') ,
booleanParam(name: 'value3', defaultValue: false, description: '') 
    ])
])


stage('stash'){

 Loop here // 
 
    node('$selected'){

 


    }
}

CodePudding user response:

Do you want to do something like the below?

node {
    properties([
    parameters([

booleanParam(name: 'value1', defaultValue: false, description: '') ,
booleanParam(name: 'value2', defaultValue: false, description: '') ,
booleanParam(name: 'value3', defaultValue: false, description: '') 
    ])
])

    stage('Stash') { 
       def list = []
       if("$value1" == "true") {
           list.add("value1")
       }
       if("$value2" == "true") {
           list.add("value2")
       }
       if("$value3" == "true") {
           list.add("value3")
       }
       
       list.each { node ->
            echo "$node"
            node('$node'){}
       }
    }
}
  • Related