Skip to content

Commit

Permalink
JENKINS-25600 fix user abort
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyMarshall committed Nov 16, 2014
1 parent d29b3cb commit 2ffbffa
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/main/java/hudson/plugins/xshell/XShellBuilder.java
Expand Up @@ -137,26 +137,32 @@ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,

Long startTime = System.currentTimeMillis();

while(child.isAlive()){

baos.flush();
String s = baos.toString();
baos.reset();

listener.getLogger().print(s);
listener.getLogger().flush();

if ((this.regexToKill != null) && (this.regexToKill.length() > 0) && (r.matcher(s).find())){
LOG.log(Level.FINEST, "Matched failure in log");
child.kill();
listener.getLogger().println("Matched <" + this.regexToKill +"> in output. Terminated");
}else if( (timeAllowed > 0) && ((System.currentTimeMillis() - startTime) / 1000) > timeAllowed){
LOG.log(Level.FINEST, "Timed out");
child.kill();
listener.getLogger().println("Timed out <" + this.timeAllocated +">. Terminated");
}else{
Thread.sleep(2);
}
try {
while (child.isAlive()) {

baos.flush();
String s = baos.toString();
baos.reset();

listener.getLogger().print(s);
listener.getLogger().flush();

if ((this.regexToKill != null) && (this.regexToKill.length() > 0) && (r.matcher(s).find())) {
LOG.log(Level.FINEST, "Matched failure in log");
child.kill();
listener.getLogger().println("Matched <" + this.regexToKill + "> in output. Terminated");
} else if ((timeAllowed > 0) && ((System.currentTimeMillis() - startTime) / 1000) > timeAllowed) {
LOG.log(Level.FINEST, "Timed out");
child.kill();
listener.getLogger().println("Timed out <" + this.timeAllocated + ">. Terminated");
} else {
Thread.sleep(2);
}
}
} catch (InterruptedException intEx) {
LOG.log(Level.FINEST, "Aborted by user");
child.kill();
listener.getLogger().println("Aborted by User. Terminated");
}

baos.flush();
Expand Down

0 comments on commit 2ffbffa

Please sign in to comment.