Skip to content

Instantly share code, notes, and snippets.

@dbr
Created September 9, 2013 12:52
Show Gist options
  • Save dbr/6495186 to your computer and use it in GitHub Desktop.
Save dbr/6495186 to your computer and use it in GitHub Desktop.
Delete failed builds for a job in Jenkins
def job = Jenkins.instance.getItem("the_job_name")
job.getBuilds().each {
if(it.result == Result.FAILURE){
// Delete failed job
it.delete()
}
}
@JoSSte
Copy link

JoSSte commented Oct 9, 2023

I had some issues with this. on multibranch pipelines Using getItemByFullName instead worked

def job = Jenkins.instance.getItemByFullName("jobname/branchname")

job.getBuilds().each {
  if(it.result == Result.FAILURE){
    // Delete failed job
    it.delete()
  }
}

@harryg-bosch
Copy link

harryg-bosch commented Aug 16, 2024

That is because of the folder in the name, not only for multibranch.
So getItemByFullName is needed whenever you have folders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment