Search code examples
htmljenkinsgroovyjenkins-plugins

How to parse HTML content to Jenkins parameters through groovy script?


I have created a dynamic text-box though Active choices Reactive reference parameter. I want to parse the content that user enters in this dynamic textbox to the build section of the Jenkins.

Below is what I have done till now Sample UI Screen 1

When the User selects "City" as input a textbox populates as shown below Sample UI Screen 2

Below is the groovy script used to populate the dynamic input box

if (Country.equals("City")) {

html=
'''<!DOCTYPE HTML>
      <input type = "text"
             id = "myText"
   />
  </p>

  </html>
  '''
  return html
  } 

else
  {
  return ["Invalid"]
  }

I want to parse the content "Delhi" to build section of Jenkins.I have tried ${path} or $path, $html, $id but it is not accessible.

Can someone please help?


Solution

  • Finally got the solution

    Code snippet

    if (Country.equals("city")) {
    
    html=
    '''
    <p>
       <input type = "text" id = "myText" name="value" >
    </p>
    <hr>
    '''
    return html
    
    } 
    
    else
    {
    return ["Invalid"]
    }
    

    The value passed in the text box path can be directly parsed as $path in the execute shell option.