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?
Asked
Active
Viewed 902 times
0
-
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 Answers
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
-
Thank you, that was helpful! I have one more question, can I change name for build directories - now, builds are stored in /jobs/$JOB_NAME/build/$BUILD_ID. Can I save them by name that differs from BUILD_ID? – Milica Matić Apr 02 '18 at 12:23
-