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}") } 
6
  • You have the response here: stackoverflow.com/questions/40195720/… Commented Dec 12, 2017 at 7:42
  • yeah tried that as well, the result is not what I am expecting. Attaching the code. Commented Dec 12, 2017 at 8: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? Commented Dec 12, 2017 at 8: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. Commented Dec 12, 2017 at 9: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) Commented Dec 12, 2017 at 9:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.