I am trying to write a feature update for the Enhanced Old Build Discarder plugin that will trigger the Workspace Cleanup plugin to clear external workspaces set up using the External Workspace Manager plugin by aiming to have it that:
These conditions aim to avoid workspace bloat, whereby upstream job workspaces kept for reuse in downstream jobs will not require manual maintenance to avoid indefinite growth in large projects.
I have experimented with monitoring the fingerprints for every individual build, but this has so far been ineffective. It requires that every build in every job in a Jenkins instance be scanned and indexed after every build discard, until it finally reaches the point where no build fingerprints indicate the usage of a given workspace, at which point it can be cleared. This is very resource intensive.
The current implementation I am experimenting with scans all artifact fingerprints after every build discard until it is observed that a given artifact is no longer seen to have been used in a build. Once all the artifacts in workspace have this property, that workspace is cleared with the Workspace Cleanup plugin. This is at least less resource intensive than the previous implementation, though it will still be costly in projects with many artifacts.
Does this implementation seem sensible? Does anyone know of a better one? Also, does anyone know of an existing plugin that scans artifact fingerprint data, and ideally looks at the usage of that artifact? I am finding lacking precedent for these kinds of operations via my own code searches.