提交 eec30751 编写于 作者: J Jesse Glick

[FIXED JENKINS-9913] At least print a diagnostic to the build log if we are...

[FIXED JENKINS-9913] At least print a diagnostic to the build log if we are waiting on a checkpoint.
上级 3ca7fbf4
......@@ -28,6 +28,7 @@ import hudson.tasks.Recorder;
import hudson.tasks.Builder;
import hudson.tasks.junit.JUnitResultArchiver;
import hudson.scm.SCM;
import javax.annotation.Nonnull;
/**
* Provides a mechanism for synchronizing build executions in the face of concurrent builds.
......@@ -141,7 +142,18 @@ public final class CheckPoint {
* If the build (represented by the calling executor thread) is aborted while it's waiting.
*/
public void block() throws InterruptedException {
Run.waitForCheckpoint(this);
Run.waitForCheckpoint(this, null, null);
}
/**
* Like {@link #block()} but allows for richer logging.
* @param listener an optional listener to which
* @param waiter a description of what component is requesting the wait, such as {@link Descriptor#getDisplayName}
* @throws InterruptedException if the build is aborted while waiting
* @since 1.528
*/
public void block(@Nonnull BuildListener listener, @Nonnull String waiter) throws InterruptedException {
Run.waitForCheckpoint(this, listener, waiter);
}
/**
......
......@@ -1403,7 +1403,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
/**
* @see CheckPoint#block()
*/
/*package*/ static void waitForCheckpoint(CheckPoint id) throws InterruptedException {
/*package*/ static void waitForCheckpoint(CheckPoint id, @CheckForNull BuildListener listener, @CheckForNull String waiter) throws InterruptedException {
while(true) {
Run b = RunnerStack.INSTANCE.peek().getBuild().getPreviousBuildInProgress();
if(b==null) return; // no pending earlier build
......@@ -1413,7 +1413,7 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
Thread.sleep(0);
continue;
}
if(runner.checkpoints.waitForCheckPoint(id))
if(runner.checkpoints.waitForCheckPoint(id, listener, waiter))
return; // confirmed that the previous build reached the check point
// the previous build finished without ever reaching the check point. try again.
......@@ -1449,13 +1449,19 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
notifyAll();
}
protected synchronized boolean waitForCheckPoint(CheckPoint identifier) throws InterruptedException {
protected synchronized boolean waitForCheckPoint(CheckPoint identifier, @CheckForNull BuildListener listener, @CheckForNull String waiter) throws InterruptedException {
final Thread t = Thread.currentThread();
final String oldName = t.getName();
t.setName(oldName+" : waiting for "+identifier+" on "+getFullDisplayName());
t.setName(oldName + " : waiting for " + identifier + " on " + getFullDisplayName() + " from " + waiter);
try {
while(!allDone && !checkpoints.contains(identifier))
boolean first = true;
while (!allDone && !checkpoints.contains(identifier)) {
if (first && listener != null && waiter != null) {
listener.getLogger().println(Messages.Run__is_waiting_for_a_checkpoint_on_(waiter, getFullDisplayName()));
}
wait();
first = false;
}
return checkpoints.contains(identifier);
} finally {
t.setName(oldName);
......
......@@ -4,6 +4,7 @@ import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.CheckPoint;
import hudson.Launcher;
import hudson.model.Describable;
import java.io.IOException;
......@@ -22,7 +23,11 @@ public enum BuildStepMonitor {
STEP {
public boolean perform(BuildStep bs, AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
CheckPoint cp = new CheckPoint(bs.getClass().getName(),bs.getClass());
cp.block();
if (bs instanceof Describable) {
cp.block(listener, ((Describable) bs).getDescriptor().getDisplayName());
} else {
cp.block();
}
try {
return bs.perform(build,launcher,listener);
} finally {
......@@ -32,7 +37,11 @@ public enum BuildStepMonitor {
},
BUILD {
public boolean perform(BuildStep bs, AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
CheckPoint.COMPLETED.block();
if (bs instanceof Describable) {
CheckPoint.COMPLETED.block(listener, ((Describable) bs).getDescriptor().getDisplayName());
} else {
CheckPoint.COMPLETED.block();
}
return bs.perform(build,launcher,listener);
}
};
......
......@@ -156,7 +156,7 @@ public class JUnitResultArchiver extends Recorder implements MatrixAggregatable
action.setData(data);
CHECKPOINT.block();
CHECKPOINT.block(listener, getDescriptor().getDisplayName());
} catch (AbortException e) {
if (build.getResult() == Result.FAILURE)
......
......@@ -205,6 +205,7 @@ ResultTrend.StillFailing=Still failing
ResultTrend.StillUnstable=Still unstable
ResultTrend.Success=Success
ResultTrend.Unstable=Unstable
Run._is_waiting_for_a_checkpoint_on_={0} is waiting for a checkpoint on {1}
Run.BuildAborted=Build was aborted
Run.MarkedExplicitly=This record is explicitly marked to be kept.
Run.Permissions.Title=Run
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册