Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1017,14 +1017,29 @@ private final class NodePrintListener implements GraphListener.Synchronous {
@Override public InputStream getLogInputStream() throws IOException {
// Inefficient but probably rarely used anyway.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
getLogText().writeRawLogTo(0, baos);
long pos = 0;
while (true) {
long pos2 = getLogText().writeLogTo(pos, baos);
if (pos2 <= pos) {
break;
}
pos = pos2;
}
return new ByteArrayInputStream(baos.toByteArray());
}

@Override public void doConsoleText(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("text/plain;charset=UTF-8");
try (OutputStream os = rsp.getCompressedOutputStream(req)) {
getLogText().writeLogTo(0, os);
// Similar to writeWholeLogTo but terminates even if !logText.complete:
long pos = 0;
while (true) {
long pos2 = getLogText().writeLogTo(pos, os);
if (pos2 <= pos) {
break;
}
pos = pos2;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.jenkinsci.plugins.workflow.steps.SynchronousStepExecution;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import org.junit.Ignore;
Expand Down Expand Up @@ -254,4 +255,14 @@ static class Execution extends SynchronousStepExecution<Void> {
b.writeWholeLogTo(System.out);
}

@Test public void doConsoleText() throws Exception {
WorkflowJob p = r.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("@NonCPS def giant() {(0..19999).join('\\n')}; echo giant(); semaphore 'wait'", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("wait/1", b);
assertThat(r.createWebClient().goTo(b.getUrl() + "consoleText", "text/plain").getWebResponse().getContentAsString(), containsString("\n12345\n"));
SemaphoreStep.success("wait/1", null);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
}

}