Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
854 views
in Technique[技术] by (71.8m points)

jenkins - Active choice reactive parameter from single json file

I am having a json file as

  { "data": [{"location" : "EU",
              "env": ["DEV", "PRD", "UAT"]},
             {"location" : "US",
              "env": ["DEV", "PRD", "UAT", "DR", "VD"]}
]}

I am trying below groovy script to have Active choice reactive parameter


import groovy.json.JsonSlurperClassic
List Locations = []
def file_data = new File('<above json file path>').text
def jsonParser = new JsonSlurperClassic()
def data = jsonParser().parseText(file_data)
for (details in data.data){
  Locations.add(details.location)
}
return Locations

I am getting Locations correctly as Parameters, however, I want to use the same file again and try to return environments based on Location using the Active Choice Reactive parameter. I tried multiple options but did not get any luck. Any help will be much appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found the solution by my own:

I used the Active Choice Reactive Parameter with the following groovy script:

import groovy.json.JsonSlurperClassic

def file_data = new File('<above json file path>').text
def jsonParser = new JsonSlurperClassic()
def data = jsonParser().parseText(file_data)
for (details in data.data){
  if (Locations == details.location){
         return details.env
}
}

I used reference Parameter as Locations from the Active Choice parameter.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...