1
- function Invoke-LoggedCommand
1
+ . $PSScriptRoot / ../ logging.ps1
2
+
3
+ function Invoke-LoggedMsbuildCommand
2
4
{
3
5
[CmdletBinding ()]
4
6
param
@@ -8,12 +10,26 @@ function Invoke-LoggedCommand
8
10
[switch ] $GroupOutput ,
9
11
[int []] $AllowedExitCodes = @ (0 )
10
12
)
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
+ )
11
28
12
- $pipelineBuild = !! $env: TF_BUILD
13
29
$startTime = Get-Date
14
30
15
- if ($pipelineBuild -and $ GroupOutput ) {
16
- Write-Host " ##[group] $Command "
31
+ if ($GroupOutput ) {
32
+ LogGroupStart $Command
17
33
} else {
18
34
Write-Host " > $Command "
19
35
}
@@ -22,22 +38,22 @@ function Invoke-LoggedCommand
22
38
Push-Location $ExecutePath
23
39
}
24
40
41
+ if (! $OutputProcessor ) {
42
+ $OutputProcessor = { param ($line ) $line }
43
+ }
44
+
25
45
try {
26
- Invoke-Expression $Command
46
+ Invoke-Expression $Command | Foreach-Object { & $OutputProcessor $_ }
27
47
28
48
$duration = (Get-Date ) - $startTime
29
49
30
- if ($pipelineBuild -and $ GroupOutput ) {
31
- Write-Host " ##[endgroup] "
50
+ if ($GroupOutput ) {
51
+ LogGroupEnd
32
52
}
33
53
34
54
if ($LastExitCode -notin $AllowedExitCodes )
35
55
{
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 "
41
57
}
42
58
else {
43
59
Write-Host " Command succeeded ($duration )`n "
0 commit comments