Home > Mobile >  Get Jenkins filtered job param value using xpath
Get Jenkins filtered job param value using xpath

Time:07-12

I have the below xml from the jenkins job data. I am trying extract the value for the selected name yaml_data inside the paramters..

I am using below url to filter the data but it still lists all the name and value of the parameters.

https://jenkins.myorg.com/job/architecture-shared-services/job/nyjobdata/lastBuild/api/xml?tree=actions[parameters[name[contains(text(),yaml_data)],value]]
<workflowRun _>
    <action _>
        <parameter _>
            <name>yaml_data</name>
            <value>mycoredatahere</value>
        </parameter>
        <parameter _>
            <name>artifact_no_ext</name>
            <value>../pom</value>
        </parameter>
        <parameter _>
            <name>artifact_repository</name>
            <value>myorg-io-maven-hosted</value>
        </parameter>
        <parameter _>
            <name>release</name>
            <value>build</value>
        </parameter>
        <parameter _>
            <name>build_name</name>
            <value>maven</value>
        </parameter>
</action>
</workflowRun>

CodePudding user response:

Try the following URL and the Xpath.

https://jenkins.myorg.com/job/architecture-shared-services/job/nyjobdata/lastBuild/api/xml?xpath=//parameter[name='yaml_data']/value

CodePudding user response:

@ycr has provided the correct answer, this just expands a bit more information based on the above question

You were nearly there, but your request is asking to display the tree: /xml?tree=

What you actually want to request is the parameter tag with its values from the xml api where the parameter name has a specific text by using xpath as you noted in the question, so that should be: /xml?xpath=

Append the url filter after api with:

/xml?xpath=//parameter[name[contains(text(),'yaml_data')]]

(where ' is the unicode character for apostrophe - so essentially you are sending this : 'yaml_data')

the result returned should be the following:

   <parameter _>
       <name>yaml_data</name>
       <value>mycoredatahere</value>
   </parameter>

You're full url query based on the above question will be:

https://jenkins.myorg.com/job/architecture-shared-services/job/nyjobdata/lastBuild/api/xml?xpath=//parameter[name[contains(text(),'yaml_data')]]

If you want the value only, then add a /value at the end of the query, the result returned should be the following:

       <value>mycoredatahere</value>

You're full url query will be:

https://jenkins.myorg.com/job/architecture-shared-services/job/nyjobdata/lastBuild/api/xml?xpath=//parameter[name[contains(text(),'yaml_data')]]/value
  • Related