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

[JENKINS-26411] Handle ChannelClosedException as well

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