简体   繁体   中英

How to read multiple attributes using xpath and based on that trigger the jenkins job

I am having an xml file(executeRM.xml) with contents as mentioned below.

<r1> <n1 name="component1" version="14.0" state="ToBeInstalled"/> <n2 name="Component2" version="13.0" state="Installed"/> <n3 name="Component3" version="12.0" state="TobeInstalled"></r1>

I have used "FS trigger-Monitor files" and is an every one minute schedule, where I have given the full path of the above xml file. Now I want to write an xpath query, which will trigger the job only when state will be "ToBeInstalled" for any of the 3 components or all. I have written the below xpath query, but the job itself is not getting triggered.

/r1/n1[@name='Component1' and @state='ToBeInstalled'] /r1/n2[@name='Component2' and @state='ToBeInstalled'] /r1/n3[@name='Component3' and @state='ToBeInstalled']

According to the FSTrigger help:

Poll the content of the specified XML file. You have to give XPath expressions. A build is triggered if the value of XPath expressions have changed between 2 polls.

Are you sure your xPath

/r1/n1[@name='Component1' and @state='ToBeInstalled'] /r1/n2[@name='Component2' and @state='ToBeInstalled'] /r1/n3[@name='Component3' and @state='ToBeInstalled']

is correct? what you have seems like 3 separate xPaths.

Even if you just use /r1/n1[@name='Component1' and @state='ToBeInstalled'] this just selects n1, a node that has no text value, so it never changes (that's just my theory).

I was able to get it to trigger by just using /r1/n1/@state for example, but I don't think this will give the control you want (and you may get multiple builds triggered).

I think you need more information on how the value of XPath expression is evaluated. You might ask the maintainer for further information at the plugin site .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM