I am trying get durations of last10 builds of a QuickBuild configuration and the duration of each step in the configuration in a groovy script. Any suggestion is appreciated.
Thank you in advance,
ptring
Description
I am trying get durations of last10 builds of a QuickBuild configuration and the duration of each step in the configuration in a groovy script. Any suggestion is appreciated.
Thank you in advance,
ptring
groovy:
import com.pmease.quickbuild.SearchCriteria;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
def statsConf = system.configurationManager.get("root");
def totalBuildDuration = 0;
def totalBuildCount = 0;
def totalStepDurationMap = [:];
def totalStepCountMap = [:];
def criterions = [Restrictions.eq("configuration", statsConf)] as Criterion[];
for (eachBuild in system.buildManager.search(new SearchCriteria(criterions, new Order[]{Order.desc("id")}), 0, 10)) {
if (eachBuild.duration != null) {
totalBuildDuration += eachBuild.duration;
totalBuildCount++;
}
for (eachEntry in eachBuild.stepRuntimes.entrySet()) {
if (eachEntry.value.duration != null) {
totalStepDurationMap[eachEntry.key] = totalStepDurationMap.get(eachEntry.key, 0) + eachEntry.value.duration;
totalStepCountMap[eachEntry.key] = totalStepCountMap.get(eachEntry.key, 0) + 1;
}
}
}
logger.info("average build duration: " + (totalBuildDuration / totalBuildCount));
for (entry in totalStepDurationMap.entrySet()) {
logger.info("average duration for step " + entry.key + ": " + entry.value / totalStepCountMap[entry.key]);
}