0
votes

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?

1
You can use groovy post build to delete previous builds by name or whatever parameter that you wantMor Lajb

1 Answers

0
votes

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.