Skip to content

Commit

Permalink
[JENKINS-72181] Restore flushed output for groovy CLI command (#8622)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck authored Oct 20, 2023
1 parent f613605 commit 8f5167d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/cli/GroovyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected int run() throws Exception {
final String scriptListenerCorrelationId = String.valueOf(System.identityHashCode(this));

Binding binding = new Binding();
binding.setProperty("out", new ScriptListener.ListenerWriter(new PrintWriter(new OutputStreamWriter(stdout, getClientCharset()), true), GroovyCommand.class, null, scriptListenerCorrelationId, User.current()));
binding.setProperty("out", new PrintWriter(new ScriptListener.ListenerWriter(new OutputStreamWriter(stdout, getClientCharset()), GroovyCommand.class, null, scriptListenerCorrelationId, User.current()), true));
binding.setProperty("stdin", stdin);
binding.setProperty("stdout", stdout);
binding.setProperty("stderr", stderr);
Expand Down
4 changes: 3 additions & 1 deletion test/src/test/java/jenkins/model/ScriptListenerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public void groovyCliUsageIsLogged() {
logging.record(DefaultScriptListener.class.getName(), Level.FINEST).capture(100);

InputStream scriptStream = new ByteArrayInputStream(script.getBytes());
new CLICommandInvoker(j, "groovy").withArgs("=").withStdin(scriptStream).invoke();
final CLICommandInvoker.Result result = new CLICommandInvoker(j, "groovy").withArgs("=").withStdin(scriptStream).invoke();
final String stdout = result.stdout();
assertThat(stdout, containsString("hello from groovy CLI"));

{ // DefaultScriptListener
final List<String> messages = logging.getMessages();
Expand Down

0 comments on commit 8f5167d

Please sign in to comment.