jenkinsci / build-history-manager-plugin

Jenkins plugin that allows to define which builds should be removed and which preserved. Several decision factors such as date, number or result can be taken into account
https://plugins.jenkins.io/build-history-manager/
MIT License
4 stars 11 forks source link

Can we express these requirements with the plugin? #89

Open olivierdagenais opened 1 year ago

olivierdagenais commented 1 year ago

What feature do you want to see added?

Given these requirements:

Is it possible to implement with the build-history-manager plugin?

Here are some examples/test scenarios:

  1. Suppose my job has 1 run a day, for each of 20 days. We should end up with the last 15 runs kept.
  2. Suppose my job has 2 runs a day, for each of 20 days. We should end up with the last 20 runs kept (i.e. 2 runs a day for the last 10 days - runs older than 10 days are gone).
  3. Suppose my job has 2 runs a day, for the first 10 days, then 10 days without runs. We should end up with the last 15 runs kept (i.e. we're only keeping based on "The 15 most recent builds are always kept, no matter their age", because the other runs have been deleted).
  4. Suppose my job has 15 runs a day, for each of 20 days. We should end up with the last 150 runs kept (15 * 10).

It feels like we would need a BuildPosition condition, which compares against a monotonically-increasing counter of runs (assuming the latest run starts at 1), such that we would be able to craft the configuration to have the following rules:

  1. conditions: [BuildPosition(maxBuildPosition: 15)], continueAfterMatch: false
  2. conditions: [BuildAgeRange(maxDaysAge: 10)], continueAfterMatch: false
  3. actions: [DeleteBuild()]

What do you think?

Thanks!

Upstream changes

n/a

damianszczepanik commented 11 months ago

I believe you have implemented properly conditions and actions. I think you don't need to create new BuildPosition because you can use https://github.com/jenkinsci/build-history-manager-plugin/blob/master/src/main/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/MatchEveryBuildCondition.java#L12 and configure it so it is executed 15 times https://github.com/jenkinsci/build-history-manager-plugin/blob/master/src/main/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/Rule.java#L31