// wait for the completion
int appearsCancelledCount = 0;
while (true) {
Thread.sleep(1000);
CurrentBuildState b = c.getCurrentStateByNumber(dynamicBuild.getNumber());
if (b != null) { // its building or is done
if (b.isBuilding()) {
continue;
} else {
Result buildResult = b.getResult();
if (buildResult != null) {
return b;
}
}
} else { // not building or done, check queue
Queue.Item qi = c.getQueueItem();
if (qi == null) {
appearsCancelledCount++;
listener.getLogger().println(c.getName() + " appears cancelled: " + appearsCancelledCount);
} else {
appearsCancelledCount = 0;
}
if (appearsCancelledCount >= 5) {
listener.getLogger().println(Messages.MatrixBuild_AppearsCancelled(ModelHyperlinkNote.encodeTo(c)));
return new CurrentBuildState("COMPLETED", Result.ABORTED);
}
}
}
}