Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -75,4 +75,10 @@ public class PipelineRunOptions extends PipelineOptions {
description = "Disable writing build logs to stdout. " +
"Plugins that handle build logs will process them as usual")
public boolean noBuildLogs = false;

@CommandLine.Option(names = { "-wlit", "--write-log-init-timeout" },
description = "Initializing build log forwarding to stdout may fail if the build log has not been created yet. " +
" This option defines the maximum time (in seconds) to wait for build log creation." +
" Defaults to 1 second.")
public int writeLogInitTimeoutSeconds = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public int run(PipelineRunOptions runOptions) throws Exception {
b = f.getStartCondition().get();

if (!runOptions.noBuildLogs) {
writeLogTo(System.out);
writeLogTo(System.out, runOptions.writeLogInitTimeoutSeconds);
}

f.get(); // wait for the completion
Expand Down Expand Up @@ -156,24 +156,23 @@ private CauseAction createCauseAction(String cause) {
return new CauseAction(c);
}

private void writeLogTo(PrintStream out) throws IOException, InterruptedException {
final int retryCnt = 10;

// read output in a retry loop, by default try only once
private void writeLogTo(PrintStream out, int timeoutSeconds) throws IOException, InterruptedException {
// read output in a retry loop,
// writeWholeLogTo may fail with FileNotFound
// exception on a slow/busy machine, if it takes
// longish to create the log file
int retryInterval = 100;
for (int i=0;i<=retryCnt;) {
long timeoutMillis = timeoutSeconds * 1000;
long startTime = System.currentTimeMillis();
while (true) {
try {
b.writeWholeLogTo(out);
break;
}
catch (FileNotFoundException | NoSuchFileException e) {
if ( i == retryCnt ) {
if ( System.currentTimeMillis() - startTime > timeoutMillis ) {
throw e;
}
i++;
Thread.sleep(retryInterval);
}
}
Expand Down