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

Powershell treats warnings as errors

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Component/s: durable-task-plugin
    • Labels:
      None
    • Environment:
      Latest Jenkins LTS, Durable-task plugin v2.21
    • Similar Issues:

      Description

      After upgrading to the latest Jenkins LTS & durable task plugin (v1.21) our pipelines fail on warnings.

      Pipeline:

      node() {
          bat 'C:\\Python27\\python.exe -c "import warnings;warnings.warn(\'future\', FutureWarning)"'
      
          powershell 'C:\\Python27\\python.exe -c "import warnings;warnings.warn(\'future\', FutureWarning)"'
      }
      

      Output:
      2018-03-08 19:47:13 [src] Running batch script
      2018-03-08 19:47:14
      2018-03-08 19:47:14 d:\src>C:\Python27\python.exe -c "import warnings;warnings.warn('future', FutureWarning)"
      2018-03-08 19:47:17 -c:1: FutureWarning: future
      [Pipeline] powershell
      2018-03-08 19:47:18 [src] Running PowerShell script
      2018-03-08 19:47:20 powershell.exe : -c:1: FutureWarning: future
      2018-03-08 19:47:20 At D:\src@tmp\durable-4343e8b5\powershellWrapper.ps1:3 char:1
      2018-03-08 19:47:20 + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -File ...
      2018-03-08 19:47:20 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      2018-03-08 19:47:20 + CategoryInfo : NotSpecified: (-c:1: FutureWarning: future:Strin g) [], RemoteException
      2018-03-08 19:47:20 + FullyQualifiedErrorId : NativeCommandError
      2018-03-08 19:47:20

      This returns in "1" exit code, causing the pipeline to fail.

      So somehow, somewhere, the warning is transformed / interpreted as an error.

        Attachments

          Activity

          Hide
          svanoort Sam Van Oort added a comment -

          Released with version 1.22

          Show
          svanoort Sam Van Oort added a comment - Released with version 1.22
          Hide
          kkkuba Jakub Michalec added a comment -

          Gabriel Loewen related to https://jenkins.io/blog/2017/07/26/powershell-pipeline/ - Failed step caused by a non-empty error stream, in our jobs we use:

          def status = powershell returnStatus: true, script: """ . .\\scripts\\someScript.ps1" """
          
          if(status != 0) { powershell ("Write-Error \"Ooops, an error occured\"") }

          If anything goes wrong it should fail job and run post action, after that fix (upgrade to 1.22) job goes further.

           

          Adding explicit exit 1, should fix it from our perspective, but from my perspective write-error should stop execution

          Show
          kkkuba Jakub Michalec added a comment - Gabriel Loewen related to https://jenkins.io/blog/2017/07/26/powershell-pipeline/  - Failed step caused by a non-empty error stream, in our jobs we use: def status = powershell returnStatus: true , script: """ . .\\scripts\\someScript.ps1" """ if (status != 0) { powershell ( "Write-Error \" Ooops, an error occured\"") } If anything goes wrong it should fail job and run post action, after that fix (upgrade to 1.22) job goes further.   Adding explicit exit 1, should fix it from our perspective, but from my perspective write-error should stop execution
          Hide
          gabloe Gabriel Loewen added a comment -

          Write-Error does not typically fail a PowerShell script unless you set ErrorActionPreference to "Stop" or explicitly pass -ErrorAction to the cmdlet.

          Show
          gabloe Gabriel Loewen added a comment - Write-Error does not typically fail a PowerShell script unless you set ErrorActionPreference to "Stop" or explicitly pass -ErrorAction to the cmdlet.
          Hide
          gabloe Gabriel Loewen added a comment -

          E.g. the error stream is technically ignored if your error action proference is not set to "Stop"

          Show
          gabloe Gabriel Loewen added a comment - E.g. the error stream is technically ignored if your error action proference is not set to "Stop"
          Show
          gabloe Gabriel Loewen added a comment - Here is a reference to PowerShell preference variables: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-6

            People

            • Assignee:
              gabloe Gabriel Loewen
              Reporter:
              wouterslob Wouter Slob
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: