@@ -150,7 +150,8 @@ function Write-PesterHostMessage {
150150 $message = " $ ( $message -replace ' (?m)^' , " $fg$bg " ) $ ( $ANSIcodes.ResetAll ) "
151151
152152 & $SafeCommands [' Write-Host' ] - Object $message - NoNewLine:$NoNewLine
153- } else {
153+ }
154+ else {
154155 if ($RenderMode -eq ' Plaintext' ) {
155156 if ($PSBoundParameters.ContainsKey (' ForegroundColor' )) {
156157 $null = $PSBoundParameters.Remove (' ForegroundColor' )
@@ -627,7 +628,7 @@ function Get-WriteScreenPlugin ($Verbosity) {
627628
628629 if ($PesterPreference.Output.CIFormat.Value -in ' AzureDevops' , ' GithubActions' ) {
629630 $errorMessage = (Format-ErrorMessage @formatErrorParams ) -split [Environment ]::NewLine
630- Write-CIErrorToScreen - CIFormat $PesterPreference.Output.CIFormat.Value - Header $errorHeader - Message $errorMessage
631+ Write-CIErrorToScreen - CIFormat $PesterPreference.Output.CIFormat.Value - CILogLevel $PesterPreference .Output.CILogLevel.Value - Header $errorHeader - Message $errorMessage
631632 }
632633 else {
633634 Write-PesterHostMessage - ForegroundColor $ReportTheme.Fail $errorHeader
@@ -700,7 +701,7 @@ function Get-WriteScreenPlugin ($Verbosity) {
700701
701702 if ($PesterPreference.Output.CIFormat.Value -in ' AzureDevops' , ' GithubActions' ) {
702703 $errorMessage = (Format-ErrorMessage @formatErrorParams ) -split [Environment ]::NewLine
703- Write-CIErrorToScreen - CIFormat $PesterPreference.Output.CIFormat.Value - Header $errorHeader - Message $errorMessage
704+ Write-CIErrorToScreen - CIFormat $PesterPreference.Output.CIFormat.Value - CILogLevel $PesterPreference .Output.CILogLevel.Value - Header $errorHeader - Message $errorMessage
704705 }
705706 else {
706707 Write-PesterHostMessage - ForegroundColor $ReportTheme.Fail $errorHeader
@@ -775,6 +776,10 @@ function Get-WriteScreenPlugin ($Verbosity) {
775776 throw " Unsupported CI format '$ ( $PesterPreference.Output.CIFormat.Value ) '"
776777 }
777778
779+ if ($PesterPreference.Output.CILogLevel.Value -notin ' Error' , ' Warning' ) {
780+ throw " Unsupported CI log level '$ ( $PesterPreference.Output.CILogLevel.Value ) '"
781+ }
782+
778783 $humanTime = " $ ( Get-HumanTime ($_test.Duration )) ($ ( Get-HumanTime $_test.UserDuration ) |$ ( Get-HumanTime $_test.FrameworkDuration ) )"
779784
780785 if ($PesterPreference.Debug.ShowNavigationMarkers.Value ) {
@@ -817,7 +822,7 @@ function Get-WriteScreenPlugin ($Verbosity) {
817822
818823 if ($PesterPreference.Output.CIFormat.Value -in ' AzureDevops' , ' GithubActions' ) {
819824 $errorMessage = (Format-ErrorMessage @formatErrorParams ) -split [Environment ]::NewLine
820- Write-CIErrorToScreen - CIFormat $PesterPreference.Output.CIFormat.Value - Header " $margin [-] $out $humanTime " - Message $errorMessage
825+ Write-CIErrorToScreen - CIFormat $PesterPreference.Output.CIFormat.Value - CILogLevel $PesterPreference .Output.CILogLevel.Value - Header " $margin [-] $out $humanTime " - Message $errorMessage
821826 }
822827 else {
823828 Write-PesterHostMessage - ForegroundColor $ReportTheme.Fail " $margin [-] $out " - NoNewLine
@@ -920,7 +925,7 @@ function Get-WriteScreenPlugin ($Verbosity) {
920925
921926 if ($PesterPreference.Output.CIFormat.Value -in ' AzureDevops' , ' GithubActions' ) {
922927 $errorMessage = (Format-ErrorMessage @formatErrorParams ) -split [Environment ]::NewLine
923- Write-CIErrorToScreen - CIFormat $PesterPreference.Output.CIFormat.Value - Header $errorHeader - Message $errorMessage
928+ Write-CIErrorToScreen - CIFormat $PesterPreference.Output.CIFormat.Value - CILogLevel $PesterPreference .Output.CILogLevel.Value - Header $errorHeader - Message $errorMessage
924929 }
925930 else {
926931 Write-PesterHostMessage - ForegroundColor $ReportTheme.BlockFail $errorHeader
@@ -945,6 +950,10 @@ function Format-CIErrorMessage {
945950 [ValidateSet (' AzureDevops' , ' GithubActions' , IgnoreCase)]
946951 [string ] $CIFormat ,
947952
953+ [Parameter (Mandatory )]
954+ [ValidateSet (' Error' , ' Warning' , IgnoreCase)]
955+ [string ] $CILogLevel ,
956+
948957 [Parameter (Mandatory )]
949958 [string ] $Header ,
950959
@@ -962,20 +971,33 @@ function Format-CIErrorMessage {
962971
963972 # header task issue error, so it gets reported to build log
964973 # https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=powershell#example-log-an-error
965- $headerTaskIssueError = " ##vso[task.logissue type=error] $Header "
966- $lines.Add ($headerTaskIssueError )
974+ # https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=powershell#example-log-a-warning-about-a-specific-place-in-a-file
975+ switch ($CILogLevel ) {
976+ " Error" { $logIssueType = ' error' }
977+ " Warning" { $logIssueType = ' warning' }
978+ Default { $logIssueType = ' error' }
979+ }
980+
981+ $headerLoggingCommand = " ##vso[task.logissue type=$logIssueType ] $Header "
982+ $lines.Add ($headerLoggingCommand )
967983
968984 # Add subsequent messages as errors, but do not get reported to build log
969985 foreach ($line in $Message ) {
970- $lines.Add (" ##[error ] $line " )
986+ $lines.Add (" ##[$logIssueType ] $line " )
971987 }
972988 }
973989 elseif ($CIFormat -eq ' GithubActions' ) {
974990
975991 # header error, so it gets reported to build log
976992 # https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
977- $headerError = " ::error::$ ( $Header.TrimStart ()) "
978- $lines.Add ($headerError )
993+ # https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message
994+ switch ($CILogLevel ) {
995+ " Error" { $headerWorkflowCommand = " ::error::$ ( $Header.TrimStart ()) " }
996+ " Warning" { $headerWorkflowCommand = " ::warning::$ ( $Header.TrimStart ()) " }
997+ Default { $headerWorkflowCommand = " ::error::$ ( $Header.TrimStart ()) " }
998+ }
999+
1000+ $lines.Add ($headerWorkflowCommand )
9791001
9801002 # Add rest of messages inside expandable group
9811003 # https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#grouping-log-lines
@@ -998,6 +1020,10 @@ function Write-CIErrorToScreen {
9981020 [ValidateSet (' AzureDevops' , ' GithubActions' , IgnoreCase)]
9991021 [string ] $CIFormat ,
10001022
1023+ [Parameter (Mandatory )]
1024+ [ValidateSet (' Error' , ' Warning' , IgnoreCase)]
1025+ [string ] $CILogLevel ,
1026+
10011027 [Parameter (Mandatory )]
10021028 [string ] $Header ,
10031029
0 commit comments