3

I am passing a multi-line string parameter using the option "this project is parameterized" with content similar to

{"name"="aaaa", "url" = "xxxx"},
{"name"="bbbb", "url" = "yyyy"}

Following is the piece of code through which I am able to get the each element:

node ('docker-maven-slave')
{
  def string = params.details.split("\n") 
  echo "size is "+string.size()  
  for (i =0; i < string.size(); i++)
  { 
    echo string[i]
  }
}

How do I access the specific value of each element? Like "name" and "url".

Is this the right approach for the such requirement? If not please suggest me the appropriate one.

Tried the same way that is suggested here:

@NonCPS    
def params() 
{
    params.details.split("\n").each {
        param -> println "${param}"
    } 
}
stage 'read-string'
node ('docker-maven-slave')
{

    params()
  //echo("${string.name}")

}
Here_2_learn
  • 5,013
  • 15
  • 50
  • 68
  • You have the response here: https://stackoverflow.com/questions/40195720/how-to-print-each-element-of-multi-line-string-parameter – Daniel Majano Dec 12 '17 at 07:42
  • yeah tried that as well, the result is not what I am expecting. Attaching the code. – Here_2_learn Dec 12 '17 at 08:00
  • have you think about the possibility of using the file parameter and passing a json file for example and to parse it using the JsonSlurper class? – Daniel Majano Dec 12 '17 at 08:44
  • I agree that using file parameter may work, but to provide more flexibility to the user, need to pass the parameters while building the job. – Here_2_learn Dec 12 '17 at 09:11
  • Have you disabled the "Use Groovy Sandbox" option of the pipeline when have you tested with the @NonCPS scope? You are using the same name for the function and the object from which you are calling to details method (params) – Daniel Majano Dec 12 '17 at 09:16
  • Yes, disabled as suggested – Here_2_learn Dec 12 '17 at 09:18

0 Answers0