简体   繁体   中英

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.

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

Here is a sample of json output of the url:

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 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?

Use the /api/xml format:

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

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:

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

and another for version:

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

References

I am struggling to write xPath for Jenkins XML API to get only the builds for a job that has a specific value for a parameter. Assume I have Job - 'MyJob' and it has several parameters one of wich is 'SomeParameterName'. I want to filter and get only those builds which ran with SomeParameterName = 'SomeValue'. Please help!

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