title: Getting a second parameter based on the first parameter in Jenkins
body: <p>I have a task where my Jenkins job needs two parameters for build. The first specifies the application name and can be either QA, Dev, Prod etc and the second is a server which is dependent on the first one. </p>
  
  <p>Example: If I chose the app name as QA, the second parameter should display values like QAServer1, QAServer2, QAServer3. </p>
  
  <p>I'm using <code>Active Choices Plugin</code> (<a href="https://wiki.jenkins.io/display/JENKINS/Active+Choices+Plugin" rel="nofollow noreferrer">https://wiki.jenkins.io/display/JENKINS/Active+Choices+Plugin</a>) to get this done but facing an problem in fetching the second parameter contents. </p>
  
  <p>Snapshots:
  <a href="https://i.stack.imgur.com/rbLoE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rbLoE.png" alt="enter image description here"></a></p>
  
  <p>For obtaining the second parameter, I've written a Groovy code which reads the respective files of the selected first parameter and gets the details.</p>
  
  <p>code:</p>
  
  <pre><code>#!/usr/bin/env groovy
  import hudson.model.*
  def Appliname = System.getenv("APPNAME")
  //println Appliname
  def list1 = []
  def directoryName = "C:/Users/Dev/Desktop/JSONSTest"
  def fileSubStr = Appliname
  def filePattern = ~/${fileSubStr}/
  def directory = new File(directoryName)
  def findFilenameClosure =
  {
     if (filePattern.matcher(it.name).find())
     {
        def jsoname = it.name
        def jsoname1 = jsoname.reverse().take(9).reverse()
        list1.add(jsoname1.substring(1,4))
        String listAsString =  "[\'${list1.join("', '")}\']"
        println "return"+listAsString
     }
  
  }
  directory.eachFileRecurse(findFilenameClosure)
  </code></pre>
  
  <p>The above code will print the output as <code>return['QAServer1', 'QAServer2']</code> which i want to use it as input for the second parameter. </p>
  
  <p>Snapshot of Second parameter:</p>
  
  <p><a href="https://i.stack.imgur.com/SRtaD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SRtaD.png" alt="enter image description here"></a></p>
  
  <p>Somehow the Groovy script is not being executed and second parameter value remains empty. How can i get this done dynamically. Am i following the right away to it. Kindly help me figure out. TIA</p>