Skip to content

Commit

Permalink
[JENKINS-54929] Always flush the output logger on the TaskListener
Browse files Browse the repository at this point in the history
 - Extract the logger out of the TaskListener and pass it to the
   stdout/stderr methods of the Launcher
 - Trap all errors and force a flush of the logger once the command
   has completed
  • Loading branch information
stevendpclark authored and Valentin Delaye committed Jan 31, 2023
1 parent 431aa39 commit 3a7342d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/org/jenkinsci/plugins/ansible/CLIRunner.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.ansible;

import java.io.IOException;
import java.io.PrintStream;
import java.util.Map;

import hudson.FilePath;
Expand Down Expand Up @@ -42,10 +43,17 @@ public CLIRunner(Run<?, ?> build, FilePath ws, Launcher launcher, TaskListener l
public boolean execute(ArgumentListBuilder args, Map<String, String> environment)
throws IOException, InterruptedException
{
return launcher.launch()
.pwd(ws)
.envs(environment)
.cmds(args)
.stdout(listener).join() == 0;
PrintStream logger = listener.getLogger();
try {
return launcher.launch()
.pwd(ws)
.envs(environment)
.cmds(args)
.stdout(logger)
.stderr(logger).join() == 0;
}
finally {
logger.flush();
}
}
}

0 comments on commit 3a7342d

Please sign in to comment.