提交 555e2d59 编写于 作者: O Oliver Gondža

[JENKINS-26411] Handle ChannelClosedException as well

上级 b0351d21
......@@ -38,6 +38,7 @@ import hudson.model.Fingerprint.RangeSet;
import hudson.model.labels.LabelAtom;
import hudson.model.listeners.RunListener;
import hudson.model.listeners.SCMListener;
import hudson.remoting.ChannelClosedException;
import hudson.remoting.RequestAbortedException;
import hudson.scm.ChangeLogParser;
import hudson.scm.ChangeLogSet;
......@@ -760,13 +761,10 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
canContinue = mon.perform(bs, AbstractBuild.this, launcher, listener);
} catch (RequestAbortedException ex) {
// Channel is closed, do not continue
final Node node = getCurrentNode();
listener.hyperlink("/" + node.toComputer().getUrl() + "log", "Slave went offline during the build");
listener.getLogger().println();
final OfflineCause offlineCause = node.toComputer().getOfflineCause();
if (offlineCause != null) {
listener.error(offlineCause.toString());
}
reportBrokenChannel(listener);
} catch (ChannelClosedException ex) {
// Channel is closed, do not continue
reportBrokenChannel(listener);
} catch (RuntimeException ex) {
ex.printStackTrace(listener.error("Build step failed with exception"));
......@@ -787,6 +785,16 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
return canContinue;
}
private void reportBrokenChannel(BuildListener listener) throws IOException {
final Node node = getCurrentNode();
listener.hyperlink("/" + node.toComputer().getUrl() + "log", "Slave went offline during the build");
listener.getLogger().println();
final OfflineCause offlineCause = node.toComputer().getOfflineCause();
if (offlineCause != null) {
listener.error(offlineCause.toString());
}
}
private String getBuildStepName(BuildStep bs) {
if (bs instanceof Describable<?>) {
return ((Describable<?>) bs).getDescriptor().getDisplayName();
......
......@@ -6,6 +6,7 @@ import static org.junit.Assert.*;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.Launcher;
import hudson.remoting.VirtualChannel;
import hudson.slaves.DumbSlave;
import hudson.slaves.OfflineCause;
import hudson.util.OneShotEvent;
......@@ -166,10 +167,13 @@ public class ExecutorTest {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
VirtualChannel channel = launcher.getChannel();
Node node = build.getBuiltOn();
e.signal(); // we are safe to be interrupted
for (;;) {
// Keep using the channel
build.getBuiltOn().getClockDifference();
channel.call(node.getClockDifferenceCallable());
Thread.sleep(100);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册