From: Michael Jeanson Date: Thu, 17 Oct 2019 15:48:18 +0000 (-0400) Subject: jjb: Split gerrit category by build type X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6c7048dc0dbe08c2db631198ce93f7ffec25c4bd;p=lttng-ci.git jjb: Split gerrit category by build type Signed-off-by: Michael Jeanson --- diff --git a/jobs/babeltrace.yaml b/jobs/babeltrace.yaml index c307dd6..da6ba00 100644 --- a/jobs/babeltrace.yaml +++ b/jobs/babeltrace.yaml @@ -350,7 +350,7 @@ - throttle: option: 'category' categories: - - 'gerrit' + - 'gerrit-{buildtype}' - job-template: name: dev_gerrit_babeltrace_winbuild @@ -389,7 +389,7 @@ - throttle: option: 'category' categories: - - 'gerrit' + - 'gerrit-winbuild' <<: *babeltrace_build_axes_defaults <<: *babeltrace_build_builders_win diff --git a/scripts/gerrit/system-clean.groovy b/scripts/gerrit/system-clean.groovy new file mode 100644 index 0000000..56a39d1 --- /dev/null +++ b/scripts/gerrit/system-clean.groovy @@ -0,0 +1,98 @@ +import hudson.matrix.* +import hudson.model.* +import jenkins.model.* + +import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritCause; +import com.sonymobile.tools.gerrit.gerritevents.dto.attr.Change; + +// Iterate over all jobs and find the ones that have a hudson.plugins.git.util.BuildData +// as an action. +// +// We then clean it by removing the useless array action.buildsByBranchName +// + +def jobPattern = "dev_gerrit_.*" + +def matchedJobs = Jenkins.instance.items.findAll { job -> + job.name =~ /$jobPattern/ +} + +for (job in matchedJobs) { + println("job: " + job.name); + + def changes = [] + + for (build in job.getBuilds()) { + println(" build: " + build.number); + + // Skip currently building builds + if (build.isBuilding()) { + println(" Is building, skip it."); + continue + } + + // Keep only the last build of a Gerrit Change + if (build.getCause(GerritCause.class) != null && + build.getCause(GerritCause.class).getEvent() != null && + build.getCause(GerritCause.class).getEvent().getChange() != null) { + + Change change = build.getCause(GerritCause.class).getEvent().getChange() + + if (changes.contains(change)) { + println(" Is not the latest for change " + change.getId() + ", delete it."); + build.delete() + continue + } else { + changes.add(change) + } + } + + // Delete successful and aborted builds + if (build.result.toString() == 'SUCCESS' || build.result.toString() == 'ABORTED') { + println(" Is SUCCESSFUL / ABORTED, delete it."); + build.delete() + continue + } + + + // It is possible for a build to have multiple BuildData actions + // since we can use the Mulitple SCM plugin. + def gitActions = build.getActions(hudson.plugins.git.util.BuildData.class) + if (gitActions != null) { + for (action in gitActions) { + action.buildsByBranchName = new HashMap(); + hudson.plugins.git.Revision r = action.getLastBuiltRevision(); + if (r != null) { + for (branch in r.getBranches()) { + action.buildsByBranchName.put(branch.getName(), action.lastBuild) + } + } + build.actions.remove(action); + build.actions.add(action); + build.save(); + } + } + + if (job instanceof MatrixProject) { + for (run in build.getRuns()) { + println(" run: " + run); + + gitActions = run.getActions(hudson.plugins.git.util.BuildData.class) + if (gitActions != null) { + for (action in gitActions) { + action.buildsByBranchName = new HashMap(); + hudson.plugins.git.Revision r = action.getLastBuiltRevision(); + if (r != null) { + for (branch in r.getBranches()) { + action.buildsByBranchName.put(branch.getName(), action.lastBuild) + } + } + run.actions.remove(action); + run.actions.add(action); + run.save(); + } + } + } + } + } +}