Reputation: 1045
I run pwsh scripts in a CI pipeline. I use $PSStyle.OutputRendering = 'PlainText'
to ensure the results are returned in plain text. This works for general output, however, for some reason it isn't applying to errors thrown:
> throw "Some error"
[31;1mException: [0m
[31;1m[36;1mLine |[0m
[31;1m[36;1m[36;1m 17 | [0m [36;1mthrow "Some error"[0m
[31;1m[36;1m[36;1m[0m[36;1m[0m[36;1m | [31;1m ~~~~~~~~~~~~~~~~~~[0m
[31;1m[36;1m[36;1m[0m[36;1m[0m[36;1m[31;1m[31;1m[36;1m | [31;1mSome error[0m
How do I get errors to be rendered as plain text as well?
For context, I'm running this in OpenShift pipelines (Tekton), here is the entirety of the TaskRun code:
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: test-output-rendering
spec:
taskSpec:
steps:
- image: mcr.microsoft.com/powershell
script: |
#!/usr/bin/env pwsh
echo '> $PSStyle.OutputRendering = PlainText'
$PSStyle.OutputRendering = 'PlainText'
echo '> throw "Some error"'
throw "Some error"
As an example, the OutputRendering
setting is working correctly for normal output:
- image: mcr.microsoft.com/powershell
script: |
#!/usr/bin/env pwsh
echo '> Get-Item . | Format-List'
Get-Item . | Format-List
echo '> $PSStyle.OutputRendering = PlainText'
$PSStyle.OutputRendering = 'PlainText'
echo '> Get-Item . | Format-List'
Get-Item . | Format-List
> Get-Item . | Format-List
Directory:
[32;1mName : [0m/
[32;1mCreationTime : [0m6/10/2024 10:00:55 PM
[32;1mLastWriteTime : [0m6/10/2024 10:00:55 PM
[32;1mLastAccessTime : [0m6/10/2024 10:00:58 PM
[32;1mMode : [0md-r--
[32;1mLinkType : [0m
[32;1mTarget : [0m
> $PSStyle.OutputRendering = PlainText
> Get-Item . | Format-List
Directory:
Name : /
CreationTime : 6/10/2024 10:00:55 PM
LastWriteTime : 6/10/2024 10:00:55 PM
LastAccessTime : 6/10/2024 10:00:58 PM
Mode : d-r--
LinkType :
Target :
Upvotes: 2
Views: 179