简体   繁体   中英

Console output of “Powershell” Jenkins step appears with delay

I have a Jenkins pipeline. One of the steps is powershell which executes a powershell script. The script contains several Echo statements that should inform about the script execution.

I'd expect the texts issued with Echo to immediately appear in the Jenkins job's console.

The problem is that they do appear but delayed. I have an impression that the output is posponed until the script has finished its work. But that makes those echo calls useless.

How can I achieve that what I write with Echo appears immediately in the Jenkins job's console?

Actually, the Jenkins job used windows bat until recently, and then all the echo calls appeared immediately in Jenkins. Then I changed to Powershell (because I wanted to do some things in parallel), and now experience the problem.

I have read about the many CmdLets that can be used ( Write-Verbose , Write-Information etc.) and tried them, but the effect is the same: The ouput apperars but delayed. Write-Host is not allowed in Jenkins jobs and is generally considered not well suited for the task.

Thank you for any hints.

Echo is just a alias in Powershell, in fact it doesnt run the bash 'echo' command, it runs a CMDLet. With the Command: Get-Alias | ? {$_.name -like "echo*"} Get-Alias | ? {$_.name -like "echo*"} Get-Alias | ? {$_.name -like "echo*"} your can see, witch CMDLet is used instead 'Write-Output'. To list all Alias you can run Get-Alias

Try the Output with the .Net method:

[system.console]::WriteLine("My Output")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM