<< Back to previous view

[QB-2424] Add options to Build Cleanup strategy to keep recommended or promoted builds
Created: 30/Apr/15  Updated: 08/May/15

Status: Open
Project: QuickBuild
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major
Reporter: Justin Georgeson Assigned To: Robin Shen
Resolution: Unresolved Votes: 1
Remaining Estimate: Unknown Time Spent: Unknown
Original Estimate: Unknown


 Description   
Have an independent checkbox for each that, when checked, the automatic build cleanup keeps the indicated builds.

 Comments   
Comment by Don Ross [ 06/May/15 03:16 PM ]
I think that this is a common-enough scenario that it should not be necessary for everyone who needs it to implement a custom script.
Comment by Robin Shen [ 06/May/15 11:26 PM ]
We have received different requirements for this from different customers, for instance, some of them want to preserve 1 year of recommended builds, while preserve one month of oridinary builds, and some of them even want to preserve builds with certain variables. So we develop a sample script in tutorial demonstrating so that different users can modify it to satisfy very different requirements.
Comment by Justin Georgeson [ 07/May/15 01:47 PM ]
I'm trying to use the script, and somewhere between 1500-2000 builds in the configuration history, the script crashes running out of heap space. Those are the long-lived builds that are prompting me to look at enabling a cleanup strategy n the first place.

Also, I can't seem to work out how to check if a build has been promoted, it throws an exception about lazy loading when I reference the collection returned by the promotedTo() method.

We understand that different customers have different use cases. But implementing this improvement doesn't take away the option to use a custom script as demoed. The checkboxes could be displayed only when the user selects the "by count" or "by days" strategy from the combobox.
Comment by Justin Georgeson [ 07/May/15 03:06 PM ]
The script fails running out of heap space somewhere between 1500 and 2000 builds in the configuration's history. These are the large builds I'm trying to cleanup in the first place.

Barring that, I'm getting an exception

java.lang.UnsupportedOperationException
    at com.pmease.quickbuild.persistence.AgentTransaction.registerSynchronization(AgentTransaction.java:30)
    at com.pmease.quickbuild.entitymanager.impl.DefaultBuildManager.delete(DefaultBuildManager.java:229)
    at com.pmease.quickbuild.entitymanager.BuildManager$delete.call(Unknown Source)

Using the script below

groovy:
import com.pmease.quickbuild.*;

def targetConf = system.configurationManager.get(vars.getValue("rootConfiguration"))
if (targetConf == null)
  throw new QuickbuildException("Unable to find target configuration.")
def builds = system.buildManager.getBuilds(targetConf)
logger.info("Found '" + builds.size() + "'")

// reverse build order so that most recent build comes at head of the list
builds = builds.reverse()
for (int i=0; i<builds.size(); i++) {
  def buildToCheck = builds.get(i)
  if (i>1000) {
    if (buildToCheck.isRecommended()) {
      logger.info("Keeping recommended build '" + buildToCheck.version + "'")
    } else {
      logger.info("Removing build {}...", buildToCheck.version)
      system.buildManager().delete(buildToCheck)
    }
  }
}
Comment by Robin Shen [ 07/May/15 11:27 PM ]
Please run this script as server instead of agent to avoid the UnsupportedOperationException. Also to avoid the LazyInitializationException, please call buildManager.getPromotedTo(build) instead of calling build.getPromotedTo() directly.
Comment by Justin Georgeson [ 08/May/15 02:08 PM ]
Thanks, those tips worked. I still can't run the script for a configuration 2000+ builds in it's history though.

I don't think the scripted cleanup configuration is very practical when you have several hundred configurations to which you'll have to add either a cleanup child config or a post-build script to trigger a build of a parameterized cleanup config.
Comment by Robin Shen [ 08/May/15 11:20 PM ]
To avoid the OOM error, either increase the heap memory of the server, or use build manager to search builds page by page (the search method).
Generated at Sat Jul 12 12:51:45 UTC 2025 using JIRA 189.