0

I have Jenkins job with parameters. Every build is named by number and name that is read from parameter (#1-build1, #2-example1, #3-build2, #4-example2). Is it possible to configure Jenkins to delete jobs by name and not by how old it is. In my example, if I issue new build named #5-example3, I want #2-example1 to be removed, and not #1-build1. Is there a plugin for removing builds by some filter?

Milica Matić
  • 13
  • 1
  • 3
  • You can use groovy post build to delete previous builds by name or whatever parameter that you want – Mor Lajb Mar 29 '18 at 20:05

1 Answers1

0

Here is a Groovy Script that can do the job. But please replace the condition as per your logic.

Jenkins.instance.getItemByFullName('temp').builds.findAll { it.number.toString().contains '<your build name pattern to delete>' }.each { it.delete() }

Please add this as a build step in your job. This will simply do as you want. If need any help, please comment here. Hope this helps.

SV Madhava Reddy
  • 1,858
  • 2
  • 15
  • 33