Issue
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 _class="org.jenkinsci.plugins.workflow.job.WorkflowRun">
<action _class="hudson.model.ParametersAction">
<parameter _class="hudson.model.TextParameterValue">
<name>yaml_data</name>
<value>mycoredatahere</value>
</parameter>
<parameter _class="hudson.model.TextParameterValue">
<name>artifact_no_ext</name>
<value>../pom</value>
</parameter>
<parameter _class="hudson.model.TextParameterValue">
<name>artifact_repository</name>
<value>myorg-io-maven-hosted</value>
</parameter>
<parameter _class="hudson.model.TextParameterValue">
<name>release</name>
<value>build</value>
</parameter>
<parameter _class="hudson.model.TextParameterValue">
<name>build_name</name>
<value>maven</value>
</parameter>
</action>
</workflowRun>
Solution
@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(),%27yaml_data%27)]]
(where %27 is the unicode character for apostrophe - so essentially you are sending this : 'yaml_data'
)
the result returned should be the following:
<parameter _class="hudson.model.TextParameterValue">
<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(),%27yaml_data%27)]]
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(),%27yaml_data%27)]]/value
Answered By - djmonki
Answer Checked By - Mary Flores (JavaFixing Volunteer)