PowerShell Script steps don't print last line of output immediately

We’ve noticed that when a a running PowerShell Script step pauses partway through, the last line that was written to the console by the script is often not displayed in the Octopus Task Log until either more output is written or the step finishes.

For example, we have a script that writes a link out using Write-Host and then goes into a loop waiting for an external process to complete (using Start-Sleep to wait on each iteration). The link doesn’t get displayed in the Task Log until the loop finishes and more output is written to the console.

If we add a second Write-Host statement immediately after the link is printed and before the loop begins, then the link will be displayed but the second Write-Host statement will now be missing.

All remaining output (including the last line) also appears in the Task Log once the step completes.

Is Octopus doing some kind of buffering of the script output in the background, and not flushing the log stream to the Task Log until more output is written to the stream? Or is there some other explanation for why it might not display the last line? Is there any way we can force it to flush the output without just adding extra Write-Host statements?

We’re using PowerShell Core (v7) on Octopus Server v2022.4.8407.

Thanks!

Hi @wayne_turner_3,

Thanks for getting in touch! It looks like you are encountering the following issue.

I did some testing on my instance running the latest version and it looks to be working correctly. Upgrading to at least v2023.1.6715 will resolve this issue for you.

Here is a comparison from 2022.4.8407 to 2023.1.8699.

Let me know if this helps or if you have any further questions at all.

Best regards,
Daniel

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.