Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display all keep forever build number using Jenkins REST API for a specific job?

Tags:

jenkins

I read the following post which does what I want for all jobs (and I made it works)

List all keep-forever builds in Jenkins?

here is what I have now : http://jenkinsmediaprocessor:7880/api/xml?depth=2&xpath=/hudson/job/build[keepLog=%22true%22]/url&wrapper=forever

But I only want to display a specific task. However I don't know where to set the job name,

I tried the followings

1-) job/MYJOBNAME

2-) JOBPATH/job/MYJOBNAME

3-) replace job with MYJOBNAME

I can't make it works.

Also would it be possible to only display a list of number? Instead of having to use a grep on the *.xml.

like image 531
Cher Avatar asked Sep 03 '25 06:09

Cher


1 Answers

This works for me:

JENKINS_URL/job/JOB_NAME/api/xml?depth=2&xpath=//build[keepLog=%22true%22]/number&wrapper=forever

Sample output:

<forever>
  <number>688</number>
  <number>687</number>
</forever>

forever is a wrapper parameter. You will find more details if refer to JENKINS_URL/api:

For XPath that matches multiple nodes, you need to also specify the "wrapper" query parameter to specify the name of the root XML element to be created so that the resulting XML becomes well-formed.

like image 120
Vitalii Elenhaupt Avatar answered Sep 04 '25 23:09

Vitalii Elenhaupt