1- function Invoke-LoggedCommand
1+ . $PSScriptRoot / ../ logging.ps1
2+
3+ function Invoke-LoggedMsbuildCommand
24{
35 [CmdletBinding ()]
46 param
@@ -8,12 +10,26 @@ function Invoke-LoggedCommand
810 [switch ] $GroupOutput ,
911 [int []] $AllowedExitCodes = @ (0 )
1012 )
13+ return Invoke-LoggedCommand $Command - ExecutePath $ExecutePath - GroupOutput:$GroupOutput - AllowedExitCodes $AllowedExitCodes - OutputProcessor { param ($line ) ProcessMsBuildLogLine $line }
14+
15+ }
16+
17+ function Invoke-LoggedCommand
18+ {
19+ [CmdletBinding ()]
20+ param
21+ (
22+ [string ] $Command ,
23+ [string ] $ExecutePath ,
24+ [switch ] $GroupOutput ,
25+ [int []] $AllowedExitCodes = @ (0 ),
26+ [scriptblock ] $OutputProcessor
27+ )
1128
12- $pipelineBuild = !! $env: TF_BUILD
1329 $startTime = Get-Date
1430
15- if ($pipelineBuild -and $ GroupOutput ) {
16- Write-Host " ##[group] $Command "
31+ if ($GroupOutput ) {
32+ LogGroupStart $Command
1733 } else {
1834 Write-Host " > $Command "
1935 }
@@ -22,22 +38,22 @@ function Invoke-LoggedCommand
2238 Push-Location $ExecutePath
2339 }
2440
41+ if (! $OutputProcessor ) {
42+ $OutputProcessor = { param ($line ) $line }
43+ }
44+
2545 try {
26- Invoke-Expression $Command
46+ Invoke-Expression $Command | Foreach-Object { & $OutputProcessor $_ }
2747
2848 $duration = (Get-Date ) - $startTime
2949
30- if ($pipelineBuild -and $ GroupOutput ) {
31- Write-Host " ##[endgroup] "
50+ if ($GroupOutput ) {
51+ LogGroupEnd
3252 }
3353
3454 if ($LastExitCode -notin $AllowedExitCodes )
3555 {
36- if ($pipelineBuild ) {
37- Write-Error " ##[error]Command failed to execute ($duration ): $Command `n "
38- } else {
39- Write-Error " Command failed to execute ($duration ): $Command `n "
40- }
56+ LogError " Command failed to execute ($duration ): $Command `n "
4157 }
4258 else {
4359 Write-Host " Command succeeded ($duration )`n "
0 commit comments