Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-65599

Dynamically calling function from active choice parameter with argument not working




      Hi team,, 

      I have a requirement to dynamically populate active choice parameter reading from a json file. 

      [$class: 'ChoiceParameter', choiceType: 'PT_SINGLE_SELECT', referencedParameters:'partnerList',description: 'Select a choice', filterLength: 1, filterable: false, name: 'PartnerName', randomName: 'choice-parameter-7601235200970', script: [$class: 'GroovyScript', fallbackScript: [classpath: [], sandbox: true, script: 'return ["ERROR"]'], script: [classpath: [], sandbox: true, script: """
      return ["${getGFEPartners().join('","')}"]

      def getGFEPartners()

      { String partnerList = getGFETopology() def jsonSlurper = new JsonSlurperClassic(); def jsonParsed = jsonSlurper.parseText(partnerList); def keySet = jsonParsed.keySet(); List keyList = [] keySet.each\{keyList.add(it)}

      return keyList;

      This is working fine and PartnerName is populated from the json as expected. 


      2. Depends upon the selection in PartnerName choice, i have to populate the second choice parameter for that am using CascadeChoiceParameter, 


      [$class: 'CascadeChoiceParameter',
      choiceType: 'PT_SINGLE_SELECT',
      description: 'Select a choice',
      filterLength: 1,
      filterable: true,
      name: 'choice1',
      referencedParameters: 'PartnerName',
      script: [$class: 'GroovyScript',
      fallbackScript: [
      classpath: [],
      sandbox: true,
      script: 'return ["ERROR"]'
      script: [
      classpath: [],
      sandbox: true,
      script: """
      return ["${getGFEEnvironment(PartnerName).join('","')}"]

      def getGFEEnvironment(String partnerName)

      { String gfeTopology = getGFETopology() def jsonSlurper = new JsonSlurperClassic(); def jsonParsed = jsonSlurper.parseText(gfeTopology); def keySet = jsonParsed[partnerName].keySet(); List<String> keyList = [] keySet.each\{keyList.add(it)}

      return keyList;


      Now this is giving me error, groovy.lang.MissingPropertyException: No such property: PartnerName for class: WorkflowScript. 

      When i hardcode the PartnerName and call the function like script: """
      return ["${getGFEEnvironment("KeyToFetch").join('","')}"]

       It is working as expected. Could you please guide me what and where am i missing this, am already stuck with the requirement for more than 2 days now. 



          There are no comments yet on this issue.


            kinow Bruno P. Kinoshita
            sathishprakasam_jenkins Sathish
            0 Vote for this issue
            1 Start watching this issue