Skip to content

Commit

Permalink
[FIXED JENKINS-27419] Properly handle scripts that call exit without /b.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Dec 2, 2015
1 parent d652a99 commit c0edb1d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Expand Up @@ -54,7 +54,7 @@ public String getScript() {
}
BatchController c = new BatchController(ws);

c.getBatchFile1(ws).write(String.format("call \"%s\" > \"%s\" 2>&1\r\necho %%ERRORLEVEL%% > \"%s\"\r\n",
c.getBatchFile1(ws).write(String.format("cmd /c \"%s\" > \"%s\" 2>&1\r\necho %%ERRORLEVEL%% > \"%s\"\r\n",
c.getBatchFile2(ws),
c.getLogFile(ws),
c.getResultFile(ws)
Expand Down
Expand Up @@ -30,19 +30,25 @@
import hudson.util.StreamTaskListener;
import java.io.ByteArrayOutputStream;
import java.io.File;
import org.apache.commons.io.output.TeeOutputStream;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

public class WindowsBatchScriptTest {

@Rule public JenkinsRule j = new JenkinsRule();

//@Issue("JENKINS-25678")
@BeforeClass public static void windows() {
Assume.assumeTrue("These tests are only for Windows", File.pathSeparatorChar == ';');
}

@Issue("JENKINS-25678")
@Test public void spaceInPath() throws Exception {
Assume.assumeTrue("This test is only for Windows", File.pathSeparatorChar == ';');
StreamTaskListener listener = StreamTaskListener.fromStdout();
FilePath ws = j.jenkins.getRootPath().child("space in path");
Launcher launcher = j.jenkins.createLauncher(listener);
Expand All @@ -54,6 +60,26 @@ public class WindowsBatchScriptTest {
c.writeLog(ws, baos);
assertEquals(Integer.valueOf(0), c.exitStatus(ws, launcher));
String log = baos.toString();
System.err.print(log);
assertTrue(log, log.contains("hello world"));
c.cleanup(ws);
}

@Issue("JENKINS-27419")
@Test public void exitCommand() throws Exception {
StreamTaskListener listener = StreamTaskListener.fromStdout();
FilePath ws = j.jenkins.getRootPath().child("ws");
Launcher launcher = j.jenkins.createLauncher(listener);
Controller c = new WindowsBatchScript("echo hello world\r\nexit 1").launch(new EnvVars(), ws, launcher, listener);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TeeOutputStream tos = new TeeOutputStream(baos, System.err);
while (c.exitStatus(ws, launcher) == null) {
c.writeLog(ws, tos);
Thread.sleep(100);
}
c.writeLog(ws, tos);
assertEquals(Integer.valueOf(1), c.exitStatus(ws, launcher));
String log = baos.toString();
assertTrue(log, log.contains("hello world"));
c.cleanup(ws);
}
Expand Down

0 comments on commit c0edb1d

Please sign in to comment.