0

Team,

I want to find out the jobs in jenkins that were build 30 days ago and have not build since 30 days.

Is there any rest api or something like that which can help me to do that.

Cloudy
  • 165
  • 1
  • 3
  • 13

3 Answers3

1

Jenkins API: {JENKINS_URL}/job/{JOB_NAME}/api/json?tree=allBuilds[url,result,timestamp,name,description,actions]
will give you all the builds ran so far for that job. And then you can iterate this JSON using JAVA or your preferred code language to match your search criteria which is in your case timestamp.

psalvi21
  • 143
  • 5
0

You can use the Jenkins script console. For example this is a code which shows you builds having defined build step.

def findBuildContainStep(searchClass) {
def jobs = jenkins.model.Jenkins.instance.getAllItems(AbstractProject.class).toArray()
for(int j = 0 ; j < jobs.size(); j++) {
    if (jobs[j].class == hudson.model.FreeStyleProject.class) {
        def steps = jobs[j].getActions().toArray()
        for(int s = 0 ; s < steps.size(); s++) {
            if (steps[s].class == searchClass) {
                println(jobs[j].getName())
            }
        }
        steps = jobs[j].getPublishers()
        steps.each {
       // somewhere here should be your condition  
            if (it.getValue().class == searchClass) {
                println(jobs[j].getName())
            }
        }
    }
  }
}
  findBuildContainStep(org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder.class)
whitediver
  • 462
  • 3
  • 12
0

This is what I used in the Jenkins Script Console:

Jenkins.instance.getAllItems(AbstractItem.class).each {
  if(!it.class.toString().contains("hudson.plugins.folder.Folder")){
    if (it.lastBuild) { 
    Date today = new Date()
    def buildDateTime = it.lastBuild.time
    def difference
    use(groovy.time.TimeCategory) {
      def duration = today - buildDateTime
      difference = duration.days
    }
    if(difference < 30){
      println(it.fullName + "," + it.lastBuild.number + "," + it.lastBuild.time + "," + difference)
    }
  } //else{
    //println(it.fullName +  "     ***** NO BUILDS FOUND *****")
    //}
  }
};