Groovy: evaluate a property with a variable in it -
a bit new groovy, trying match variable string property pulled file using configslurper. have slurper part working fine, can't seem figure out right way evaluate property variable in it. think getting warm when found evaluating-code-dynamically-in-groovy not entirely sure.
//properties.groovy jobs { foo { email="foo@email.com" } } //myscript.groovy def config = new configslurper().parse(new file('properties.groovy').touri().tourl()) list jobs = (arraylist) bazapi.getartifacts(bucket) // list of objects, foo 1 listiterator jobiterator = jobs.listiterator(); while (jobiterator.hasnext()) { object j = jobiterator.next(); job_name = "${j.name}" // email = config.jobs."${job_name}".email /* need figure out how eval */ foo_email = config.jobs.foo.email //evaluates correct property in properties.groovy //these values fed dsl illustrate println "${job_name}" // prints foo println "${email}" // prints [:] println "${foo_email}" // prints foo@email.com }
have tried
config.jobs[ j.name ].email
Comments
Post a Comment