shanwar shanwar - 1 year ago 149
JSON Question

How to find and query a specific build in Jenkins using the Python Jenkins API

We have a Jenkins job that runs builds using specific parameters.
Two of these parameters are important for me: the machine that the build is being deployed on, and the version number of the package that is deployed.


Here is a sample of json output of the url:



Using the Jenkins REST API or the Python Jenkins wrapper, how would I search for the job if I know the folder_level1 and would like to match the lab name to a job in folder_level3 to finally get the version from that URL?

Answer Source

Use the /api/xml format:


which returns the action XML node which can be queried via XPath:

Take the matching name from there to search for the data in question:

  • builtOn - the machine that the build is being deployed on
  • number - the version number of the package that is deployed

Using an XPath for each, along with a wrapper node for grouping, such as the following for builtOn:


and another for version: