简体   繁体   中英

Getting variables from Jenkins runtime

I have several choices in my jenkins pipeline script:

`booleanParam[ name: 'VAR1', defaultValue: true, description: '']
booleanParam[ name: 'VAR2', defaultValue: true, description: '']
booleanParam[ name: 'VAR3', defaultValue: true, description: '']`

I'm trying to make a map like a ["microservice1": true, "microservice2": true, etc.] if I chose params above (tick the params) So Is there any method to get these variables from runtime? I mean Jenkins makes some map|array with all variables by itself. And I can get it with built-in function or somehow else/ Thanks in advance

I wrote just a simble code like a

def getParams() {
  def myArray = []
  if (params.VAR1) {myArray.add("var1")}
  if (params.VAR2) {myArray.add("var2")}
  if (params.VAR3) {myArray.add("var3")}
  return myArray
}

But I feel it's stupid

def toggleValues = [
    'VAR1': 'value1',
    'VAR2': 'value2',
    'VAR3': 'value3'
]

toggleValues.findAll{params[it.key] == true}.collect{it.value}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM