Any plugin to parse XML?

105 views
Skip to first unread message

Rafael Ribeiro Rezende

unread,
Mar 9, 2015, 10:23:43 AM3/9/15
to jenkins...@googlegroups.com
Is there any plugin to parse XML and extract selected fields into Environment Variables?

If not, would it make sense to implement something like this for the community?
For instance, one would provide the XML file with the content:

<project>
   
<developers>
       
<developer>
           
<id>dev1</id>
           
<name>Developer 1</name>
           
<email>devel...@email.com</email>
       
</developer>
       
<developer>
           
<id>dev2</id>
           
<name>Developer 2</name>
           
<email>devel...@email.com</email>
       
</developer>
   
</developers>
   
<organization>
       
<name>Company</name>
   
</organization>
</project>


Then, there would be an additional field where one could make the following assignment:
DEV_USER = ${project.developers[1].id}
ORGANIZATION
= ${project.organization.name}


The following environment variables would be created:
DEV_USER = dev1
ORGANIZATION
= Company


Oleg Nenashev

unread,
Mar 9, 2015, 12:03:16 PM3/9/15
to jenkins...@googlegroups.com
AFAIK there's no plugins for such purpose.

The best way to do it in Jenkins w/o plugins would be...
  1. Convert XML file to *.properties using XSLT conversion
  2. Inject environment variables using EnvInject plugin
I think a dedicated plugin (or EnvInject extension) would find some users.

Best regards,
Oleg Nenashev


понедельник, 9 марта 2015 г., 17:23:43 UTC+3 пользователь Rafael Ribeiro Rezende написал:

Les Mikesell

unread,
Mar 9, 2015, 4:04:52 PM3/9/15
to jenkinsci-users
Parsing xml always turns out to be non-trivial, so you'll probably
want access to groovy's XmlParser or XmlSlurper functionality - which
you could get from the groovy plugin. However, I think only the
'system' groovy step can add to the build job environment, and since
it runs on the master I don't see how to make it read files in the
slave's workspace.

--
Les Mikesell
lesmi...@gmail.com

Rafael Ribeiro Rezende

unread,
Mar 10, 2015, 3:52:55 PM3/10/15
to jenkins...@googlegroups.com
Hello Oleg,
When you mention XSLT, you mean to make the conversion programatically, right? Without a Jenkins plugin, but still requiring some development to make it work.
I ask because I haven't heard about an XSLT CLI or something to use out-of-the-box. I may be outdated though.

Thanks for your answer!
Rafael

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/r9j5R63M3R4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/564ad7ba-f2c0-41f7-81b5-5cbdaac2bcc9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Rafael R Rezende

Rafael Ribeiro Rezende

unread,
Mar 10, 2015, 3:59:56 PM3/10/15
to jenkinsci-users
Hello Les Mikesell,
I could give a try with the Workflow plugin, although I'm able to use it right now because our SCM is not yet compliant.
Thanks for pointing me out to those libs!

Rafael

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/r9j5R63M3R4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Rafael R Rezende

Les Mikesell

unread,
Mar 10, 2015, 4:24:11 PM3/10/15
to jenkinsci-users
On Tue, Mar 10, 2015 at 2:59 PM, Rafael Ribeiro Rezende
<rafael...@gmail.com> wrote:
> Hello Les Mikesell,
> I could give a try with the Workflow plugin, although I'm able to use it
> right now because our SCM is not yet compliant.
> Thanks for pointing me out to those libs!
>

Groovy has the most sensible xml operations I've seen anywhere - sort
of like you are working with an xml object directly instead of weird
abstractions about it.

If your job is running on the master, a system groovy step would be
able to read the file and update the build's environment. There might
be a way to get access to remote workspace files in a system groovy
step - in fact I'd expect it, but it it may be complicated. If anyone
knows, please post an example or link to docs.

Not sure about how the pieces fit together in Workflow. You may have
an issue with restrictions on the libraries you can access, either at
all or which ones are exposed to things running on the slave nodes.

--
Les Mikesell
lesmi...@gmail.com

Jesse Glick

unread,
Mar 19, 2015, 11:34:54 AM3/19/15
to jenkins...@googlegroups.com
On Tuesday, March 10, 2015 at 4:24:11 PM UTC-4, LesMikesell wrote:
Not sure about how the pieces fit together in Workflow.  You may have
an issue with restrictions on the libraries you can access, either at
all or which ones are exposed to things running on the slave nodes.

Have not tried it, but it is probably doable. Use readFile to download the file contents from the slave. Then use standard Groovy APIs to parse; you might need to wrap the details in a function marked @NonCps.

Thomas Goeppel

unread,
Sep 11, 2015, 8:17:39 AM9/11/15
to Jenkins Users

Have not tried it, but it is probably doable. Use readFile to download the file contents from the slave. Then use standard Groovy APIs to parse; you might need to wrap the details in a function marked @NonCps.

Thanks Jesse, this works.

Vikram Bansal

unread,
Sep 17, 2015, 7:50:17 PM9/17/15
to Jenkins Users
Can we have a sample please?

Thanks,

Vikram
Reply all
Reply to author
Forward
0 new messages