|
|
|
[
Permlink
| « Hide
]
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.
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.
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. 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) } } } 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.
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. 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).
|