@@ -12,6 +12,7 @@ $script:loggingCommandEscapeMappings = @( # TODO: WHAT ABOUT "="? WHAT ABOUT "%"
1212# TODO: BUG: Escape % ???
1313# TODO: Add test to verify don't need to escape "=".
1414
15+ # Specify "-Force" to force pipeline formatted output even if "$ci" is false or not set
1516function Write-PipelineTelemetryError {
1617 [CmdletBinding ()]
1718 param (
@@ -25,80 +26,101 @@ function Write-PipelineTelemetryError {
2526 [string ]$SourcePath ,
2627 [string ]$LineNumber ,
2728 [string ]$ColumnNumber ,
28- [switch ]$AsOutput )
29+ [switch ]$AsOutput ,
30+ [switch ]$Force )
2931
30- $PSBoundParameters.Remove (" Category" ) | Out-Null
32+ $PSBoundParameters.Remove (' Category' ) | Out-Null
3133
34+ if ($Force -Or ((Test-Path variable:ci) -And $ci )) {
3235 $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
3740}
3841
42+ # Specify "-Force" to force pipeline formatted output even if "$ci" is false or not set
3943function Write-PipelineTaskError {
4044 [CmdletBinding ()]
4145 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
5662 }
5763 elseif ($Type -eq ' warning' ) {
58- Write-Host $Message - ForegroundColor Yellow
59- return
64+ Write-Host $Message - ForegroundColor Yellow
65+ return
6066 }
61- }
62-
63- if (($Type -ne ' error' ) -and ($Type -ne ' warning' )) {
67+ }
68+
69+ if (($Type -ne ' error' ) -and ($Type -ne ' warning' )) {
6470 Write-Host $Message
6571 return
66- }
67- if (-not $PSBoundParameters.ContainsKey (' Type' )) {
72+ }
73+ $PSBoundParameters.Remove (' Force' ) | Out-Null
74+ if (-not $PSBoundParameters.ContainsKey (' Type' )) {
6875 $PSBoundParameters.Add (' Type' , ' error' )
69- }
70- Write-LogIssue @PSBoundParameters
71- }
76+ }
77+ Write-LogIssue @PSBoundParameters
78+ }
7279
73- function Write-PipelineSetVariable {
80+ function Write-PipelineSetVariable {
7481 [CmdletBinding ()]
7582 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 ) {
8491 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
8895 } - AsOutput:$AsOutput
89- }
90- }
96+ }
97+ }
9198
92- function Write-PipelinePrependPath {
99+ function Write-PipelinePrependPath {
93100 [CmdletBinding ()]
94101 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 ) {
99107 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+ }
102124
103125<# #######################################
104126# Private functions.
@@ -115,7 +137,8 @@ function Format-LoggingCommandData {
115137 foreach ($mapping in $script :loggingCommandEscapeMappings ) {
116138 $Value = $Value.Replace ($mapping.Token , $mapping.Replacement )
117139 }
118- } else {
140+ }
141+ else {
119142 for ($i = $script :loggingCommandEscapeMappings.Length - 1 ; $i -ge 0 ; $i -- ) {
120143 $mapping = $script :loggingCommandEscapeMappings [$i ]
121144 $Value = $Value.Replace ($mapping.Replacement , $mapping.Token )
@@ -148,7 +171,8 @@ function Format-LoggingCommand {
148171 if ($first ) {
149172 $null = $sb.Append (' ' )
150173 $first = $false
151- } else {
174+ }
175+ else {
152176 $null = $sb.Append (' ;' )
153177 }
154178
@@ -185,7 +209,8 @@ function Write-LoggingCommand {
185209 $command = Format-LoggingCommand - Area $Area - Event $Event - Data $Data - Properties $Properties
186210 if ($AsOutput ) {
187211 $command
188- } else {
212+ }
213+ else {
189214 Write-Host $command
190215 }
191216}
@@ -204,12 +229,12 @@ function Write-LogIssue {
204229 [switch ]$AsOutput )
205230
206231 $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+ }
213238 if ($AsOutput ) {
214239 return $command
215240 }
@@ -221,7 +246,8 @@ function Write-LogIssue {
221246 $foregroundColor = [System.ConsoleColor ]::Red
222247 $backgroundColor = [System.ConsoleColor ]::Black
223248 }
224- } else {
249+ }
250+ else {
225251 $foregroundColor = $host.PrivateData.WarningForegroundColor
226252 $backgroundColor = $host.PrivateData.WarningBackgroundColor
227253 if ($foregroundColor -isnot [System.ConsoleColor ] -or $backgroundColor -isnot [System.ConsoleColor ]) {
@@ -231,4 +257,4 @@ function Write-LogIssue {
231257 }
232258
233259 Write-Host $command - ForegroundColor $foregroundColor - BackgroundColor $backgroundColor
234- }
260+ }
0 commit comments