@@ -12,6 +12,7 @@ $script:loggingCommandEscapeMappings = @( # TODO: WHAT ABOUT "="? WHAT ABOUT "%"
12
12
# TODO: BUG: Escape % ???
13
13
# TODO: Add test to verify don't need to escape "=".
14
14
15
+ # Specify "-Force" to force pipeline formatted output even if "$ci" is false or not set
15
16
function Write-PipelineTelemetryError {
16
17
[CmdletBinding ()]
17
18
param (
@@ -25,80 +26,101 @@ function Write-PipelineTelemetryError {
25
26
[string ]$SourcePath ,
26
27
[string ]$LineNumber ,
27
28
[string ]$ColumnNumber ,
28
- [switch ]$AsOutput )
29
+ [switch ]$AsOutput ,
30
+ [switch ]$Force )
29
31
30
- $PSBoundParameters.Remove (" Category" ) | Out-Null
32
+ $PSBoundParameters.Remove (' Category' ) | Out-Null
31
33
34
+ if ($Force -Or ((Test-Path variable:ci) -And $ci )) {
32
35
$Message = " (NETCORE_ENGINEERING_TELEMETRY=$Category ) $Message "
33
- $PSBoundParameters .Remove ( " Message " ) | Out-Null
34
- $PSBoundParameters.Add ( " Message" , $Message )
35
-
36
- Write-PipelineTaskError @PSBoundParameters
36
+ }
37
+ $PSBoundParameters.Remove ( ' Message' ) | Out-Null
38
+ $PSBoundParameters .Add ( ' Message ' , $Message )
39
+ Write-PipelineTaskError @PSBoundParameters
37
40
}
38
41
42
+ # Specify "-Force" to force pipeline formatted output even if "$ci" is false or not set
39
43
function Write-PipelineTaskError {
40
44
[CmdletBinding ()]
41
45
param (
42
- [Parameter (Mandatory = $true )]
43
- [string ]$Message ,
44
- [Parameter (Mandatory = $false )]
45
- [string ]$Type = ' error' ,
46
- [string ]$ErrCode ,
47
- [string ]$SourcePath ,
48
- [string ]$LineNumber ,
49
- [string ]$ColumnNumber ,
50
- [switch ]$AsOutput )
51
-
52
- if (! $ci ) {
53
- if ($Type -eq ' error' ) {
54
- Write-Host $Message - ForegroundColor Red
55
- return
46
+ [Parameter (Mandatory = $true )]
47
+ [string ]$Message ,
48
+ [Parameter (Mandatory = $false )]
49
+ [string ]$Type = ' error' ,
50
+ [string ]$ErrCode ,
51
+ [string ]$SourcePath ,
52
+ [string ]$LineNumber ,
53
+ [string ]$ColumnNumber ,
54
+ [switch ]$AsOutput ,
55
+ [switch ]$Force
56
+ )
57
+
58
+ if (! $Force -And (-Not (Test-Path variable:ci) -Or ! $ci )) {
59
+ if ($Type -eq ' error' ) {
60
+ Write-Host $Message - ForegroundColor Red
61
+ return
56
62
}
57
63
elseif ($Type -eq ' warning' ) {
58
- Write-Host $Message - ForegroundColor Yellow
59
- return
64
+ Write-Host $Message - ForegroundColor Yellow
65
+ return
60
66
}
61
- }
62
-
63
- if (($Type -ne ' error' ) -and ($Type -ne ' warning' )) {
67
+ }
68
+
69
+ if (($Type -ne ' error' ) -and ($Type -ne ' warning' )) {
64
70
Write-Host $Message
65
71
return
66
- }
67
- if (-not $PSBoundParameters.ContainsKey (' Type' )) {
72
+ }
73
+ $PSBoundParameters.Remove (' Force' ) | Out-Null
74
+ if (-not $PSBoundParameters.ContainsKey (' Type' )) {
68
75
$PSBoundParameters.Add (' Type' , ' error' )
69
- }
70
- Write-LogIssue @PSBoundParameters
71
- }
76
+ }
77
+ Write-LogIssue @PSBoundParameters
78
+ }
72
79
73
- function Write-PipelineSetVariable {
80
+ function Write-PipelineSetVariable {
74
81
[CmdletBinding ()]
75
82
param (
76
- [Parameter (Mandatory = $true )]
77
- [string ]$Name ,
78
- [string ]$Value ,
79
- [switch ]$Secret ,
80
- [switch ]$AsOutput ,
81
- [bool ]$IsMultiJobVariable = $true )
82
-
83
- if ( $ci ) {
83
+ [Parameter (Mandatory = $true )]
84
+ [string ]$Name ,
85
+ [string ]$Value ,
86
+ [switch ]$Secret ,
87
+ [switch ]$AsOutput ,
88
+ [bool ]$IsMultiJobVariable = $true )
89
+
90
+ if (( Test-Path variable:ci) -And $ci ) {
84
91
Write-LoggingCommand - Area ' task' - Event ' setvariable' - Data $Value - Properties @ {
85
- ' variable' = $Name
86
- ' isSecret' = $Secret
87
- ' isOutput' = $IsMultiJobVariable
92
+ ' variable' = $Name
93
+ ' isSecret' = $Secret
94
+ ' isOutput' = $IsMultiJobVariable
88
95
} - AsOutput:$AsOutput
89
- }
90
- }
96
+ }
97
+ }
91
98
92
- function Write-PipelinePrependPath {
99
+ function Write-PipelinePrependPath {
93
100
[CmdletBinding ()]
94
101
param (
95
- [Parameter (Mandatory = $true )]
96
- [string ]$Path ,
97
- [switch ]$AsOutput )
98
- if ($ci ) {
102
+ [Parameter (Mandatory = $true )]
103
+ [string ]$Path ,
104
+ [switch ]$AsOutput )
105
+
106
+ if ((Test-Path variable:ci) -And $ci ) {
99
107
Write-LoggingCommand - Area ' task' - Event ' prependpath' - Data $Path - AsOutput:$AsOutput
100
- }
101
- }
108
+ }
109
+ }
110
+
111
+ function Write-PipelineSetResult {
112
+ [CmdletBinding ()]
113
+ param (
114
+ [ValidateSet (" Succeeded" , " SucceededWithIssues" , " Failed" , " Cancelled" , " Skipped" )]
115
+ [Parameter (Mandatory = $true )]
116
+ [string ]$Result ,
117
+ [string ]$Message )
118
+ if ((Test-Path variable:ci) -And $ci ) {
119
+ Write-LoggingCommand - Area ' task' - Event ' complete' - Data $Message - Properties @ {
120
+ ' result' = $Result
121
+ }
122
+ }
123
+ }
102
124
103
125
<# #######################################
104
126
# Private functions.
@@ -115,7 +137,8 @@ function Format-LoggingCommandData {
115
137
foreach ($mapping in $script :loggingCommandEscapeMappings ) {
116
138
$Value = $Value.Replace ($mapping.Token , $mapping.Replacement )
117
139
}
118
- } else {
140
+ }
141
+ else {
119
142
for ($i = $script :loggingCommandEscapeMappings.Length - 1 ; $i -ge 0 ; $i -- ) {
120
143
$mapping = $script :loggingCommandEscapeMappings [$i ]
121
144
$Value = $Value.Replace ($mapping.Replacement , $mapping.Token )
@@ -148,7 +171,8 @@ function Format-LoggingCommand {
148
171
if ($first ) {
149
172
$null = $sb.Append (' ' )
150
173
$first = $false
151
- } else {
174
+ }
175
+ else {
152
176
$null = $sb.Append (' ;' )
153
177
}
154
178
@@ -185,7 +209,8 @@ function Write-LoggingCommand {
185
209
$command = Format-LoggingCommand - Area $Area - Event $Event - Data $Data - Properties $Properties
186
210
if ($AsOutput ) {
187
211
$command
188
- } else {
212
+ }
213
+ else {
189
214
Write-Host $command
190
215
}
191
216
}
@@ -204,12 +229,12 @@ function Write-LogIssue {
204
229
[switch ]$AsOutput )
205
230
206
231
$command = Format-LoggingCommand - Area ' task' - Event ' logissue' - Data $Message - Properties @ {
207
- ' type ' = $Type
208
- ' code ' = $ErrCode
209
- ' sourcepath' = $SourcePath
210
- ' linenumber' = $LineNumber
211
- ' columnnumber' = $ColumnNumber
212
- }
232
+ ' type ' = $Type
233
+ ' code ' = $ErrCode
234
+ ' sourcepath' = $SourcePath
235
+ ' linenumber' = $LineNumber
236
+ ' columnnumber' = $ColumnNumber
237
+ }
213
238
if ($AsOutput ) {
214
239
return $command
215
240
}
@@ -221,7 +246,8 @@ function Write-LogIssue {
221
246
$foregroundColor = [System.ConsoleColor ]::Red
222
247
$backgroundColor = [System.ConsoleColor ]::Black
223
248
}
224
- } else {
249
+ }
250
+ else {
225
251
$foregroundColor = $host.PrivateData.WarningForegroundColor
226
252
$backgroundColor = $host.PrivateData.WarningBackgroundColor
227
253
if ($foregroundColor -isnot [System.ConsoleColor ] -or $backgroundColor -isnot [System.ConsoleColor ]) {
@@ -231,4 +257,4 @@ function Write-LogIssue {
231
257
}
232
258
233
259
Write-Host $command - ForegroundColor $foregroundColor - BackgroundColor $backgroundColor
234
- }
260
+ }
0 commit comments