+
+// Save the tag and commit IDs scheduled in the past and during this run to the
+// workspace. We save it at the end to be sure all jobs were launched. We save
+// the object IDs even in case of failure. There is no point of re-running the
+// same job is there are no code changes even in case of failure.
+println("Saving Git object IDs of previously built projects to the workspace.");
+saveCurrentIdsToWorkspace(newOldLinuxTags, linuxOnDiskPath);
+saveCurrentIdsToWorkspace(newOldToolsHeadCommits, toolsOnDiskPath);
+saveCurrentIdsToWorkspace(newOldModulesHeadCommits, modulesOnDiskPath);
+saveCurrentIdsToWorkspace(newOldUstHeadCommits, ustOnDiskPath);
+
+// Iterate over all the running jobs. Record the status of completed jobs.
+while (ongoingBuild.size() > 0) {
+ def ongoingIterator = ongoingBuild.iterator();
+ while (ongoingIterator.hasNext()) {
+ currentBuild = ongoingIterator.next();
+
+ jobName = currentBuild.getKey();
+ job_run = currentBuild.getValue();
+
+ // The isCancelled() method checks if the run was cancelled before
+ // execution. We consider such run as being aborted.
+ if (job_run.isCancelled()) {
+ println("${jobName} was cancelled before launch.")
+ abortedRuns.add(jobName);
+ isAborted = true;
+ ongoingIterator.remove();
+ } else if (job_run.isDone()) {
+
+ job_status = job_run.get();
+ println("${job_status.fullDisplayName} completed with status ${job_status.result}.");
+
+ // If the job didn't succeed, add its name to the right list so it can
+ // be printed at the end of the execution.
+ switch (job_status.result) {
+ case Result.ABORTED:
+ isAborted = true;
+ abortedRuns.add(jobName);
+ break;
+ case Result.FAILURE:
+ isFailed = true;
+ failedRuns.add(jobName);
+ break;
+ case Result.SUCCESS:
+ default:
+ break;
+ }
+
+ ongoingIterator.remove();
+ }
+ }
+
+ // Sleep before the next iteration.
+ try {
+ Thread.sleep(10000)
+ } catch(e) {
+ if (e in InterruptedException) {
+ build.setResult(hudson.model.Result.ABORTED)
+ throw new InterruptedException()
+ } else {
+ throw(e)
+ }
+ }
+}
+
+// Get log of failed runs.
+if (failedRuns.size() > 0) {
+ println("Failed job(s):");
+ for (failedRun in failedRuns) {
+ println("\t" + failedRun)
+ }
+}
+
+// Get log of aborted runs.
+if (abortedRuns.size() > 0) {
+ println("Cancelled job(s):");
+ for (cancelledRun in abortedRuns) {
+ println("\t" + cancelledRun)
+ }
+}
+
+// Mark this build as Failed if atleast one child build has failed and mark as
+// aborted if there was no failure but atleast one job aborted.
+if (isFailed) {
+ build.setResult(hudson.model.Result.FAILURE)
+} else if (isAborted) {
+ build.setResult(hudson.model.Result.ABORTED)
+}