grayaii
grayaii

Reputation: 2444

List jobs NOT using Discard Old Builds

Is there a way to get a list of Jenkins jobs that are NOT using the "Discard Old Builds" option?

I found a few jobs that people have created that are NOT using this plugin and I'm trying to enforce the usage of it:

enter image description here

Upvotes: 1

Views: 328

Answers (2)

Ravindranath Barathy
Ravindranath Barathy

Reputation: 791

How about following these steps:

  1. Get the list of jobs : <jenkins_url>/api/json?tree=jobs[name,url]
  2. Parse through each job config.xml <jenkins_url>/job/<job_name>/config.xml
  3. Look for xpath=//properties/jenkins.model.BuildDiscarderProperty

There could be much more efficient ways to do it too!

Upvotes: 1

rohit thomas
rohit thomas

Reputation: 2312

You will have to use Jenkins API(I've used JSON api for e.g.) and look for the below property

"property" : [
    {
      "_class" : "jenkins.model.BuildDiscarderProperty"
    }
  ],

If present it indicates that Discard old Builds is checked.

So you can iterate through all the jobs and the job that don't have this property is your culprits.

Hope this helps :)

Upvotes: 0

Related Questions