Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-66701

Powershell-Plugin can not output UTF-8 to console

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • powershell-plugin
    • None
    • Windows Server 2019
      Jenkins LTS 2.303.1

      It is not possible to output UTF-8 with Powershell (6+7).

      Powershell-Plugin with pwsh 7.1:
      Write-Host "UTF-8 Sign: ✅"                            >> UTF-8 Sign: �o.

      Bash-Buildstep with pswh 7.1:
      pwsh -command "Write-Host UTF-8 Sign: ✅" >> UTF-8 Sign: ✅

      I only have a Windows Jenkins environment.
      To get UTF-8 support on Windows you must start jenkins with
      -Dfile.encoding=UTF8.

      After that other plugins output UTF-8 correctly but not the Powershell plugin.

          [JENKINS-66701] Powershell-Plugin can not output UTF-8 to console

          Filipe Roque added a comment -

           
           I confirm this issue. The first of these unit tests fails on Windows:

          @Test
          public void testBuildEncodingOnWindowsWithPowerShellCore() throws Exception {
          Computer computer = r.jenkins.getComputer("");
          Assume.assumeTrue(Boolean.FALSE.equals(computer.isUnix()));
          
          PowerShellInstallation.DescriptorImpl descriptor =
           r.jenkins.getDescriptorByType(PowerShellInstallation.DescriptorImpl.class);
          ToolLocationNodeProperty.ToolLocation toolLocation
           = new ToolLocationNodeProperty.ToolLocation(descriptor,
          "DefaultWindows",
          "C:\\Program Files\\PowerShell\\7\\pwsh.exe");
          ToolLocationNodeProperty toolLocationNodeProperty = new ToolLocationNodeProperty(toolLocation);
           computer.getNode().getNodeProperties().add(toolLocationNodeProperty);
          
          FreeStyleProject project1 = r.createFreeStyleProject("project1");
           project1.getBuildersList().add(new PowerShell("Write-Host \"UTF-8 Sign: ✅\"", true, true));
          
          QueueTaskFuture<FreeStyleBuild> freeStyleBuildQueueTaskFuture = project1.scheduleBuild2(0);
          FreeStyleBuild build = freeStyleBuildQueueTaskFuture.get();
          
           r.assertLogContains("UTF-8 Sign: ✅", build);
           r.assertBuildStatusSuccess(build);
           }
          
          @Test
          public void testBuildEncodingOnWindowsWithBatch() throws Exception {
          Computer computer = r.jenkins.getComputer("");
          Assume.assumeTrue(Boolean.FALSE.equals(computer.isUnix()));
          
          FreeStyleProject project1 = r.createFreeStyleProject("project1");
           project1.getBuildersList()
           .add(new BatchFile("pwsh.exe -NonInteractive -ExecutionPolicy Bypass -Command \"Write-Host UTF-8 Sign: ✅\""));
          
          QueueTaskFuture<FreeStyleBuild> freeStyleBuildQueueTaskFuture = project1.scheduleBuild2(0);
          FreeStyleBuild build = freeStyleBuildQueueTaskFuture.get();
          
           r.assertLogContains("UTF-8 Sign: ✅", build);
           r.assertBuildStatusSuccess(build);
           }
          

          I don't really know how to fix this. There is some solutions in msbuild-plugin using chcp.

          https://github.com/jenkinsci/msbuild-plugin/pull/29
          https://github.com/jenkinsci/msbuild-plugin/pull/32

          But messing around with coding pages feels like a very bad solution. I am open to other ideas.

          Here are some other jenkins issues somewhat related:

          Filipe Roque added a comment -    I confirm this issue. The first of these unit tests fails on Windows: @Test public void testBuildEncodingOnWindowsWithPowerShellCore() throws Exception { Computer computer = r.jenkins.getComputer(""); Assume.assumeTrue( Boolean .FALSE.equals(computer.isUnix())); PowerShellInstallation.DescriptorImpl descriptor = r.jenkins.getDescriptorByType(PowerShellInstallation.DescriptorImpl.class); ToolLocationNodeProperty.ToolLocation toolLocation = new ToolLocationNodeProperty.ToolLocation(descriptor, "DefaultWindows" , "C:\\Program Files\\PowerShell\\7\\pwsh.exe" ); ToolLocationNodeProperty toolLocationNodeProperty = new ToolLocationNodeProperty(toolLocation); computer.getNode().getNodeProperties().add(toolLocationNodeProperty); FreeStyleProject project1 = r.createFreeStyleProject( "project1" ); project1.getBuildersList().add( new PowerShell( "Write-Host \" UTF-8 Sign: ✅\"", true , true )); QueueTaskFuture<FreeStyleBuild> freeStyleBuildQueueTaskFuture = project1.scheduleBuild2(0); FreeStyleBuild build = freeStyleBuildQueueTaskFuture.get(); r.assertLogContains( "UTF-8 Sign: ✅" , build); r.assertBuildStatusSuccess(build); } @Test public void testBuildEncodingOnWindowsWithBatch() throws Exception { Computer computer = r.jenkins.getComputer(""); Assume.assumeTrue( Boolean .FALSE.equals(computer.isUnix())); FreeStyleProject project1 = r.createFreeStyleProject( "project1" ); project1.getBuildersList() .add( new BatchFile( "pwsh.exe -NonInteractive -ExecutionPolicy Bypass -Command \" Write-Host UTF-8 Sign: ✅\"")); QueueTaskFuture<FreeStyleBuild> freeStyleBuildQueueTaskFuture = project1.scheduleBuild2(0); FreeStyleBuild build = freeStyleBuildQueueTaskFuture.get(); r.assertLogContains( "UTF-8 Sign: ✅" , build); r.assertBuildStatusSuccess(build); } I don't really know how to fix this. There is some solutions in msbuild-plugin using chcp. https://github.com/jenkinsci/msbuild-plugin/pull/29 https://github.com/jenkinsci/msbuild-plugin/pull/32 But messing around with coding pages feels like a very bad solution. I am open to other ideas. Here are some other jenkins issues somewhat related: https://issues.jenkins.io/browse/JENKINS-53027 https://issues.jenkins.io/browse/JENKINS-42856 https://issues.jenkins.io/browse/JENKINS-66103 https://issues.jenkins.io/browse/JENKINS-37036 https://issues.jenkins.io/browse/JENKINS-27253

            froque Filipe Roque
            martinbauer Martin Bauer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: