Build-Parallel writes only to Output stream
GreatTeacherBasshead opened this issue · comments
Let's assume we have a function func.ps1:
function Test-Function {
[CmdletBinding()]
param ()
Write-Host 'Write-Host'
Write-Output 'Write-Output'
Write-Verbose 'Write-Verbose'
Write-Information 'Write-Information'
}
And a tasks file tasks.ps1:
Enter-Build {
. func.ps1
}
task Test {
Test-Function -Verbose -InformationAction Continue
}
When I run Build-Parallel @{File='tasks.ps1'}
or even something like:
Build-Parallel @{File='tasks.ps1';Verbose=$true;InformationAction='Continue'} -Verbose -InformationAction Continue
I always get:
Start (1/1) tasks.ps1
Build (1/1) tasks.ps1:
Build Test tasks.ps1
Task /Test
Write-Output
Done /Test
Build succeeded. 1 tasks, 0 errors, 0 warnings
Build (1/1) D:\Temp\xxx\tasks.ps1 succeeded.
Tasks: 1 tasks, 0 errors, 0 warnings
Builds succeeded. 1 builds, 0 failed
It ignores all other streams except Output.
Is it expected behavior? What could you recommend, if I want to have different output verbosity (like I try to achieve with different levels of logging) in Build-Parallel?
I would say it is expected, by design. Can we improve? Let me think about this, when I am back from my holiday 😁
We may partially support some streams like Verbose
and Information
(Host
is included to Information
). As a result, records are not lost, good. But we
cannot write them in the same order as they were written. All we can do is to
propagate record batches to the caller, one after another, e.g. verbose records
first, then information records.
Thus, in a sample similar to yours the call
Build-Parallel @(
@{File='.build.ps1'; Task='Test'; Verbose=$true; InformationAction='Continue'}
)
produces
Start (1/1) C:\ROM\z\_230513_0649-ib212\.build.ps1
Build (1/1) C:\ROM\z\_230513_0649-ib212\.build.ps1:
VERBOSE: Write-Verbose
Write-Host
Write-Information
Build Test C:\ROM\z\_230513_0649-ib212\.build.ps1
Task /Test
Write-Output
Done /Test 00:00:00.0320003
Build succeeded. 1 tasks, 0 errors, 0 warnings 00:00:00.1530057
Build (1/1) C:\ROM\z\_230513_0649-ib212\.build.ps1 succeeded.
Tasks: 1 tasks, 0 errors, 0 warnings
Builds succeeded. 1 builds, 0 failed 00:00:00.3950046
Here is the branch with these changes https://github.com/nightroman/Invoke-Build/tree/work-212.
You may take Build-Parallel.ps1
from it and replace your current for local testing.
With another commit pushed to this branch, we also support InformationVariable
and this makes "logging" of information more useful.
We may choose what to use, InformationAction
or InformationVariable
or both
InformationAction
just causes the records to be "printed".InformationVariable
tells where to keep them for the analysis with full meta information preserved.
Build-Parallel @(
@{File='.build.ps1'; Task='Test'; Verbose=$true; InformationAction='Continue'; InformationVariable='InformationVariable'}
)
$InformationVariable | Select-Object Tags, MessageData | Out-String
produces
Start (1/1) C:\ROM\z\_230513_0649-ib212\2\.build.ps1
Build (1/1) C:\ROM\z\_230513_0649-ib212\2\.build.ps1:
VERBOSE: Write-Verbose
Write-Host
Write-Information
Build Test C:\ROM\z\_230513_0649-ib212\2\.build.ps1
Task /Test
Write-Output
Done /Test 00:00:00.0312487
Build succeeded. 1 tasks, 0 errors, 0 warnings 00:00:00.1405902
Build (1/1) C:\ROM\z\_230513_0649-ib212\2\.build.ps1 succeeded.
Tasks: 1 tasks, 0 errors, 0 warnings
Builds succeeded. 1 builds, 0 failed 00:00:00.4062427
Tags MessageData
---- -----------
{PSHOST} Write-Host
{} Write-Information
Hi Roman,
Thanks for the quick reply! I've tested it, and the usage of InformationVariable
looks like a proper place for having those log entries.
When could it be released?
When could it be released?
Pretty soon, hopefully today or tomorrow. I am catching up at work after the holiday...
v5.10.4