1

I'm writing a pipeline job using groovy. I need to get the info about running builds of the same job, with the build's parameters and their ids, so I can later filter it by parameters

I found these questions how to achieve that

From Jenkins, how do I get a list of the currently running jobs in JSON?

How do I Efficiently list **All** currently running jobs on Jenkins using Groovy

and the proposed solution do return the information about the jobs, but they return too many results (not only active jobs) and have other problems

For example http://jenkins.example.com/api/xml?tree=jobs[name,url,color]&xpath=/hudson/job[ends-with(color/text(),%22_anime%22)]&wrapper=jobs doesn't return any info about builds

The closest guess so far was https://jenkins.example.com/api/xml?tree=jobs[name,status,id,result,builds[number,actions[parameters[name,value]]]]&xpath=/hudson/job[name="job_name"]&wrapper=job_names&pretty=true but it returns lost of just action items and doesn't indicate which builds are active

Any help to achieve what I want is appreciated. The preferred output is JSON

Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40

1 Answers1

3

Try the below API:

https://jenkins_domain/job/test_job/api/json?tree=builds[id,building,actions[parameters[name,value]]]

But you can't really filter the results, because XPath is not supported in JSON API

greybeard
  • 2,249
  • 8
  • 30
  • 66
  • I'm having difficulty finding documentation about `tree=builds` and the available properties on a build. Does anyone know where to find that information in the Jenkins documentation? – risingfish Jan 05 '22 at 22:12