Powershell 7 pipeline output and special characters

Hey guys,
I have a simple installation of one jenkins instance in version 2.504.1 and have some encoding issues when Im using powershell 7.

Jenkins is running on a Windows Server 2022 and Powershell 7.5.0 is currently installed.

My pipeline execution looks like:

  node {
      pwsh '''
          Set-Location 'D:/jenkins-scripts'
          if ($env:JEN_TESTMODE -eq $true) {
            .\\powershell-script.ps1 `
              -parameter1 "$env:JENKINS_PARAMETER1" `
              -parameter2 "$env:JENKINS_PARAMETER2" `
              -parameter3 "$env:JENKINS_PARAMETER3" `
              -testmode `
          } else {
            .\\powershell-script.ps1 `
              -parameter1 "$env:JENKINS_PARAMETER1" `
              -parameter2 "$env:JENKINS_PARAMETER2" `
              -parameter3 "$env:JENKINS_PARAMETER3" `
          }

I was running the script with windows powershell before. The output was fine. Now I have to change to powershell 7 for several reasons and the output of special characters is broken.

I added two lines to validate the used encoding:

Write-Host "`$OutputEncoding: $($OutputEncoding.EncodingName)"
Write-Host "[Console]::OutputEncoding: $([Console]::OutputEncoding.EncodingName)"

And here is the result when im using “Write-Warning” in the powershell script:

So its looks to me, that UTF-8 is used and found several articles to this topic. I added a system wide environment variable to windows and rebooted the whole system.

JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8

Everything I found is not working. Does someone know a working solution? :slight_smile:

I really appretiate your help.

thanks in advanced

Alex

The characters have nothing to do with the encoding. Those are characters to apply different colors, all modern shells also on windows do support those color codes.
With the AnsiColor plugin you can add that support to Jenkins as well

Hi Markus,

thanks a lot for the quick anwser. I wouldnt never ever find this out :smiley:

It is working. Thanks alot!

1 Like