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

Pipeline with PowerShell 7: Write-Error Characters do not display properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • core
    • Jenkins 2.249.2, Windows 10 v2004, PowerShell 7.0.3

      I have only tested this on Windows 10, I am not sure if the same issue is present on other operating systems. Also note that this is NOT related to the PowerShell plugin (which I have not installed)but specific to using PowerShell within a pipeline.

      To replicate:

      1) Install the latest version of PowerShell on Windows 10 (PowerShell 7.0.3).

      2) Install the latest LTS version of Jenkins on Windows 10, choose the option to install the default plugins.

      3) Choose New item > Pipeline

      4) Leave all the default options alone.

      5) Copy-paste the following into the "pipeline script" section:

      pipeline {
      agent any
      stages {
      stage('Test') {
      steps {
      script

      { stdo = powershell(returnStdout: true, script: ''' Write-Error 'PowerShell 5.1: Error 1' ''') echo stdo }

      script

      { stdo = pwsh(returnStdout: true, script: ''' Write-Error 'PowerShell 7: Error 1' ''') echo stdo }

      script

      { powershell(script: ''' Write-Error 'PowerShell 5.1: Error 2' ''') }

      script

      { pwsh(script: ''' Write-Error 'PowerShell 7: Error 2' ''') }

      }
      }
      }
      }

      6) Note that the error messages print fine in PowerShell 5.1 but NOT in PowerShell 7. Also note that the build shows as "SUCCESS" despite all the errors, which seems to be an issue with both PowerShell 5.1 and PowerShell 7 unless the $ErrorActionPreference variable is set to "Stop" manually (more details here: https://www.reddit.com/r/jenkinsci/comments/jb6591/powershell_pipeline_example_doesnt_return/).

      Output:

      Running in Durability level: MAX_SURVIVABILITY
      [Pipeline] Start of Pipeline
      [Pipeline] node
      Running on Jenkins in C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\PowerShell\PowerShell-pipeline5
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Test)
      [Pipeline] script
      [Pipeline] {
      [Pipeline] powershell
      C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\PowerShell\PowerShell-pipeline5@tmp\durable-89bdf695\powershellScript.ps1 : PowerShell 5.1: Error 1
      At C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\PowerShell\PowerShell-pipeline5@tmp\durable-89bdf695\powershellHelper.ps1:54 char:9
      + &

      { & $MainScript | Out-FileNoBom -Writer $OutputWriter }

      *>&1 | ...
      + ~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellScript.ps1

      [Pipeline] echo

      [Pipeline] }
      [Pipeline] // script
      [Pipeline] script
      [Pipeline] {
      [Pipeline] pwsh

      Write-Error: C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\PowerShell\PowerShell-pipeline5@tmp\durable-8222dfc6\powershellHelper.ps1:54
      Line |
       54 |  &

      { & $MainScript | Out-FileNoBom -Writer $OutputWriter }

      *>&1 | …
       |  ~~~~~~~~~~~~~
       | PowerShell 7: Error 1
      
      [Pipeline] echo

      [Pipeline] }
      [Pipeline] // script
      [Pipeline] script
      [Pipeline]

      { [Pipeline] powershell powershell.exe : C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\PowerShell\PowerShell-pipeline5@tmp\d At C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\PowerShell\PowerShell-pipeline5@tmp\durable-c90b1f1c\powershellWrapper.ps1:3 char:1 + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (C:\WINDOWS\syst...pipeline5@tmp\d:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError urable-c90b1f1c\powershellScript.ps1 : PowerShell 5.1: Error 2 At line:1 char:1 + & 'C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins\.je ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellScript.ps1 [Pipeline] }

      [Pipeline] // script
      [Pipeline] script
      [Pipeline]

      { [Pipeline] pwsh Write-Error: PowerShell 7: Error 2 [Pipeline] }

      [Pipeline] // script
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      [Checks API] No suitable checks publisher found.
      Finished: SUCCESS

            Unassigned Unassigned
            jmcclain Jeffrey McClain
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: