Sergey Pleshakov
Sergey Pleshakov

Reputation: 8948

Get a list of currently running jenkins builds with their parameters

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

Upvotes: 1

Views: 2754

Answers (1)

Olha Obertas
Olha Obertas

Reputation: 46

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

Upvotes: 3

Related Questions