x
login Signup

Can't print multiple values using --valueOf ectool option

I am hoping to use the following command to list all resources, however it only lists the first resource.

 ectool --valueOf //resourceName getResources

Is it possible to use the valueOf option when there are multiple objects in the returned xpath response? I've tried variations of the path such as "//resource/resourcesName", "/responses/response/resources/resource/resourceName", etc. Haven't found one that gives the result I'm after.

avatar image By david 131 asked Nov 14 at 12:05 AM
more ▼
(comments are locked)
10|750 characters needed characters left

2 answers: sort voted first

Interesting, it looks like the --valueOf '' option only returns one value, not all hits from the xpath expression. So the trick is to get all the values you want into a single XML node. This works:

 ectool --valueOf '//value' evalDsl 'def r=[];getResources().each {r.push(it.resourceName)};r.join("\n")'

If this is to be run in a procedure step, you can set the shell to:

 ectool --valueOf '//value' evalDsl --dslFile "{0}"

Then the following DSL to list out your resources:

 def r=[]
 getResources().each {
   r.push(it.resourceName)
 }
 r.join("\\n")


Here's the complete DSL to create and run the procedure:

 project "Test",{
   procedure "Test",{
     step "Get Resources", shell: 'ectool --valueOf \'//value\' evalDsl --dslFile "{0}"',
       command: '''\
           def r=[]
           getResources().each {
             r.push(it.resourceName)
           }
           r.join("\\n")
       '''.stripIndent()
   }
 }
 
 runProcedure procedureName: "Test", projectName: "Test"

avatar image By gregm 2k answered Nov 14 at 12:24 AM
more ▼
(comments are locked)
avatar image lrochette Nov 14 at 02:49 PM

don't you need a transaction around the "runProcedure"?

10|750 characters needed characters left

Apparently not--it works as expected. Try it!

avatar image By gregm 2k answered Nov 15 at 03:08 PM
more ▼
(comments are locked)
avatar image lrochette Nov 15 at 03:36 PM

I was just afraid it would run the previous version of the procedure. I trust you if you say it works

10|750 characters needed characters left
Your answer
toggle preview:

Up to 8 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.