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

Powershell step in pipeline job outputs UTF-8 BOM

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • Jenkins 2.60.2
      Windows Server 2012 R2
      PSVersion 5.1.15063.502

      Plugins:
      Powershell 1.3
      Pipeline: Build Step 2.5.1
      Pipeline 2.5

      Powershell step in pipeline outputs UTF-8 BOM characters with Powershell output.

      [workspace] Running PowerShell script
      Hello
      

      If I run the same command (Write-Host "Hello") in a usual build job as a Powershell step it outputs normal output:

      [workspace] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\VALERY~1.ZAB\AppData\Local\Temp\jenkins2440165524934484537.ps1'"
      Hello
      Finished: SUCCESS
      

      Here's my powershell step code:

      powershell 'Write-Host "Hello"'
      

          [JENKINS-46496] Powershell step in pipeline job outputs UTF-8 BOM

          Darwin Sanoy added a comment - - edited

          When I updated from 1.15 to 1.17 of the Durable Task plugin, PowerShell scripts stopped executing altogether.

          There is an eternal pause right after Jenkins logs that it is starting the first powershell code.

          Prior to this, it has always output the BOM characters in Jenkins logs - but also always worked.

          When I revert this plug-in to 1.15, it starts working again.

          Everything else is right up to date as of this writing: Jenkins 2.73.3 and Blue Ocean 1.3.3

          My code is a powershell script that is part of the replicated repository.  It is called in a Blue Ocean declarative pipeline using the dot (".") invoke operator so that exit codes are consumed directly by the pipeline.

          I am running on Server 2012 R2 which has been updated to PowerShell 5.1.14409.1005.

          Here is what the call looks like:

          withEnv(["FIBUILDNAME=${jobconsolenamejenkinsvar}","TESTIMAGENAMEPREPEND=${TEST_IMAGENAME_PREPEND}"]) {
          powershell '''
          . "$PWD/Stage1-CreateWindowsAMI.ps1" -EnvironmentParams 'auto' -FIBuildName $env:FIBUILDNAME -FIBuildNumber $env:BUILD_NUMBER -CIBuildURL $env:BUILD_URL -AWSProfile 'instanceprofile' -TestImageNamePrepend $env:TESTIMAGENAMEPREPEND
          '''
          }
          

          jglick

          Darwin Sanoy added a comment - - edited When I updated from 1.15 to 1.17 of the Durable Task plugin, PowerShell scripts stopped executing altogether. There is an eternal pause right after Jenkins logs that it is starting the first powershell code. Prior to this, it has always output the BOM characters in Jenkins logs - but also always worked. When I revert this plug-in to 1.15, it starts working again. Everything else is right up to date as of this writing: Jenkins 2.73.3 and Blue Ocean 1.3.3 My code is a powershell script that is part of the replicated repository.  It is called in a Blue Ocean declarative pipeline using the dot (".") invoke operator so that exit codes are consumed directly by the pipeline. I am running on Server 2012 R2 which has been updated to PowerShell 5.1.14409.1005. Here is what the call looks like: withEnv([ "FIBUILDNAME=${jobconsolenamejenkinsvar}" , "TESTIMAGENAMEPREPEND=${TEST_IMAGENAME_PREPEND}" ]) { powershell ''' . "$PWD/Stage1-CreateWindowsAMI.ps1" -EnvironmentParams 'auto' -FIBuildName $env:FIBUILDNAME -FIBuildNumber $env:BUILD_NUMBER -CIBuildURL $env:BUILD_URL -AWSProfile 'instanceprofile' -TestImageNamePrepend $env:TESTIMAGENAMEPREPEND ''' } jglick

          Gabriel Loewen added a comment - - edited

          Hi Darwin,

          Yes, this issue has been reported and I have sent a PR which fixes the problem.  This issue happens when the workspace has spaces in the path.  For instance: "C:\Program Files (x86)\Jenkins\workspace".  You have a few options to unblock yourself until my code change makes it into the official build.  You can:

          1. Revert back to Durable Task 1.15
          2. Create a workspace for your projects in a location without any spaces in the path
          3. Clone my repo: https://github.com/gabloe/durable-task-plugin, build the plugin locally, and then install the plugin from the local build (durable-task.hpi)

          If you choose #3 just remember to update to the official plugin once my changes have been baked in.

          Thanks,

          Gabriel

          Gabriel Loewen added a comment - - edited Hi Darwin, Yes, this issue has been reported and I have sent a PR which fixes the problem.  This issue happens when the workspace has spaces in the path.  For instance: "C:\Program Files (x86)\Jenkins\workspace".  You have a few options to unblock yourself until my code change makes it into the official build.   You can: Revert back to Durable Task 1.15 Create a workspace for your projects in a location without any spaces in the path Clone my repo:  https://github.com/gabloe/durable-task-plugin , build the plugin locally, and then install the plugin from the local build (durable-task.hpi) If you choose #3 just remember to update to the official plugin once my changes have been baked in. Thanks, Gabriel

          Darwin Sanoy added a comment -

          gabloe - Thanks for the explanation - I can wait.

          I'm not sure if you can influence this, but a more proper place for machine level (not intended to be associated with a specific user) ephemeral state data like this does not have spaces.

          That is %PROGRAMDATA%\Jenkins which would usually be c:\programdata\jenkins.
          Thanks again!

          Darwin Sanoy added a comment - gabloe - Thanks for the explanation - I can wait. I'm not sure if you can influence this, but a more proper place for machine level (not intended to be associated with a specific user) ephemeral state data like this does not have spaces. That is %PROGRAMDATA%\Jenkins which would usually be c:\programdata\jenkins. Thanks again!

          Jakub Michalec added a comment - - edited

          After that fix it's much harder to debug powershell scripts, error atm:

           

          C:\CI\Jenkins\...@tmp\durable-f7d18e60\powershellWrapper.ps1 : You 
          cannot call a method on a null-valued expression.
          At C:\CI\Jenkins\...@tmp\durable-f7d18e60\powershellHelper.ps1:30 
          char:7
          +       & $MainScript *>&1 | Out-FileNoBom -FilePath $LogFile; $LastExi ...
          +       ~~~~~~~~~~~~~~~~~~
              + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
              + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellWrapper.ps1
          
          

           

          In real there was issue inside ps script (null parameter), but earlier I was getting in on Jenkins site - place when error in real occure (painfull when you have complicated ps scripts). 

           

          Jakub Michalec added a comment - - edited After that fix it's much harder to debug powershell scripts, error atm:   C:\CI\Jenkins\...@tmp\durable-f7d18e60\powershellWrapper.ps1 : You cannot call a method on a null -valued expression. At C:\CI\Jenkins\...@tmp\durable-f7d18e60\powershellHelper.ps1:30 char :7 + & $MainScript *>&1 | Out-FileNoBom -FilePath $LogFile; $LastExi ... + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellWrapper.ps1   In real there was issue inside ps script (null parameter), but earlier I was getting in on Jenkins site - place when error in real occure (painfull when you have complicated ps scripts).   

          Code changed in jenkins
          User: Sam Van Oort
          Path:
          src/main/java/org/jenkinsci/plugins/durabletask/PowershellScript.java
          src/main/resources/org/jenkinsci/plugins/durabletask/powershellHelper.ps1
          src/test/java/org/jenkinsci/plugins/durabletask/PowershellScriptTest.java
          http://jenkins-ci.org/commit/durable-task-plugin/4a06f3cc8eb9053c0bf5597a06b69163c005c3b0
          Log:
          Merge pull request #51 from gabloe/master

          Fixed JENKINS-46876, JENKINS-46508, JENKINS-46496, JENKINS-48057, and JENKINS-47797

          Compare: https://github.com/jenkinsci/durable-task-plugin/compare/7c12b3a72cb4...4a06f3cc8eb9

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Sam Van Oort Path: src/main/java/org/jenkinsci/plugins/durabletask/PowershellScript.java src/main/resources/org/jenkinsci/plugins/durabletask/powershellHelper.ps1 src/test/java/org/jenkinsci/plugins/durabletask/PowershellScriptTest.java http://jenkins-ci.org/commit/durable-task-plugin/4a06f3cc8eb9053c0bf5597a06b69163c005c3b0 Log: Merge pull request #51 from gabloe/master Fixed JENKINS-46876 , JENKINS-46508 , JENKINS-46496 , JENKINS-48057 , and JENKINS-47797 Compare: https://github.com/jenkinsci/durable-task-plugin/compare/7c12b3a72cb4...4a06f3cc8eb9

          RME added a comment -

          How quickly can this be turned around, please?

          RME added a comment - How quickly can this be turned around, please?

          Stefano Fenu added a comment - - edited

          Hi,

          I have the problem described in

          https://stackoverflow.com/questions/47527274/jenkins-pipeline-powershell-script-hangs

          One of the replies (https://stackoverflow.com/a/47829048/1953115) mentions this issue.

          So I tried approaches (described above) 2 and 3 of the following ones:

          1. Revert back to Durable Task 1.15
          2. Create a workspace for your projects in a location without any spaces in the path
          3. Clone my repo: https://github.com/gabloe/durable-task-plugin, build the plugin locally, and then install the plugin from the local build (durable-task.hpi)

          ( I could not try approach 1 as I have other plugins that seem to depend on that version)

          But my powershell command on a slave node still hangs.

          Here is the Jenkinsfile snippet:

           

                stage('install to my.server') {
                  node('my.server') {
                    bat "set"
                    powershell 'Write-Output "Hello, World!"'
                  }
                }

           

          Any idea how to fix that?

          Best regards

          Stefano

          Stefano Fenu added a comment - - edited Hi, I have the problem described in https://stackoverflow.com/questions/47527274/jenkins-pipeline-powershell-script-hangs One of the replies ( https://stackoverflow.com/a/47829048/1953115) mentions this issue. So I tried approaches (described above) 2 and 3 of the following ones: Revert back to Durable Task 1.15 Create a workspace for your projects in a location without any spaces in the path Clone my repo:  https://github.com/gabloe/durable-task-plugin , build the plugin locally, and then install the plugin from the local build (durable-task.hpi) ( I could not try approach 1 as I have other plugins that seem to depend on that version) But my powershell command on a slave node still hangs. Here is the Jenkinsfile snippet:         stage('install to my.server') {         node('my.server') {           bat "set"           powershell 'Write-Output "Hello, World!"'         }       }   Any idea how to fix that? Best regards Stefano

          Hi sfenu,

          Can you send the system information of the Jenkins master/slave where your job is getting executed? Windows version, PowerShell version, and .NET version installed. If you built the plugin out of my repo then all of the unit tests would have been executed, and they test a variety of scenarios that should have caught any issue that you described. Since the .hpi file was produced, and I'm assuming that you didn't see a bunch of errors in the output, then you shouldn't be experiencing this issue. So, I'm not sure why that approach did not work for you.

          The issue has been fixed in my bug rollup PR that was just merged into the official repo, so you should also try again once the next release is out, which should be very soon.

          Thanks,

          Gabriel

          Gabriel Loewen added a comment - Hi sfenu , Can you send the system information of the Jenkins master/slave where your job is getting executed? Windows version, PowerShell version, and .NET version installed . If you built the plugin out of my repo then all of the unit tests would have been executed, and they test a variety of scenarios that should have caught any issue that you described. Since the .hpi file was produced, and I'm assuming that you didn't see a bunch of errors in the output, then you shouldn't be experiencing this issue. So, I'm not sure why that approach did not work for you. The issue has been fixed in my bug rollup PR that was just merged into the official repo, so you should also try again once the next release is out, which should be very soon. Thanks, Gabriel

          Stefano Fenu added a comment -

          Hi,

          Thanks for your help.

          Actually the problem was simpler, as the master was ok with powershell version (5.1) but the slave was using an unsupported powershell version (2.0)

          I upgraded powershell in the slave to 4.0 and now the test powershell command works.

          Just for a complete information, I have not (yet) reverted back the steps 2 and 3:

          • Create a workspace for your projects in a location without any spaces in the path
          • Clone my repo: https://github.com/gabloe/durable-task-plugin, build the plugin locally, and then install the plugin from the local build (durable-task.hpi)

          Best Regards

          Stefano

          Stefano Fenu added a comment - Hi, Thanks for your help. Actually the problem was simpler, as the master was ok with powershell version (5.1) but the slave was using an unsupported powershell version (2.0) I upgraded powershell in the slave to 4.0 and now the test powershell command works. Just for a complete information, I have not (yet) reverted back the steps 2 and 3: Create a workspace for your projects in a location without any spaces in the path Clone my repo:  https://github.com/gabloe/durable-task-plugin , build the plugin locally, and then install the plugin from the local build (durable-task.hpi) Best Regards Stefano

          Sam Van Oort added a comment -

          Released with 1.18

          Sam Van Oort added a comment - Released with 1.18

            gabloe Gabriel Loewen
            dziki_jam Valeriy Zabawski
            Votes:
            6 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated:
              Resolved: