How to find and request a specific assembly in Jenkins using the Python Jenkins API

We have a Jenkins job that runs assemblies using specific parameters. Two of these options are important to me: the machine on which the assembly is deployed, and the version number of the deployed package.

https: // jenkinsurl / job / folder_level1 / job / folder_level2 / job / folder_level3 / job_id /

Here is an example url json output:

https: // jenkinsurl / job / folder_level1 / job / folder_level2 / job / folder_level3 / job_id / api / json

{"actions":[{"parameters":[{"name":"lab_name","value":"labA"},{"name":"version_no","value":"1.1"}]} 

Using the Jenkins REST API or the Python Jenkins shell, how do I search for a job if I know the level1 folder and would like to combine the lab name with the job in the level3 folder to finally get the version from this URL?

+6
source share
1 answer

Use the format / api / xml:

 https://jenkinsurl/job/folder_level1/api/xml 

which returns an action XML node that can be requested through XPath:

Take the appropriate name from there to search for data:

  • builtOn - the machine on which the assembly is deployed to
  • number - version number of the deployed package

Using XPath for each along with a node wrapper for grouping, for example, for builtOn:

 https://jenkinsurl/job/folder_level1/api/xml?depth=3&xpath=//fullDisplayName[contains(text(),'foo')]/following-sibling::builtOn&wrapper=builtOn_results 

and the other for the version:

 https://jenkinsurl/job/folder_level1/api/xml?depth=3&xpath=//fullDisplayName[contains(text(),'foo')]/following-sibling::number&wrapper=version_results 

References

+5
source

All Articles