Skip to content
Permalink
Browse files
Merge pull request #12 from jglick/exitCommand-JENKINS-27419
[JENKINS-27419] Properly handle scripts that call exit without /b
  • Loading branch information
jglick committed Dec 3, 2015
2 parents d652a99 + c0edb1d commit 807eca36b3ca37d00518e957940117dd1ea3df54
@@ -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)
@@ -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);
@@ -54,6 +60,26 @@
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);
}

0 comments on commit 807eca3

Please sign in to comment.