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

Powershell pipeline step: Enable selecting debug/verbose streams for console output

XMLWordPrintable

      Consider this declarative pipeline:

      Jenkinsfile
      pipeline {
          agent any
      
          stages {
              stage('Deploy') {
                  steps {
                      powershell 'Write-Verbose \'This is the verbose stream\''
                      powershell 'Write-Information \'This is the info stream\''
                  }
              }
          }
      }
      

      The console output looks like this:

      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Deploy)
      [Pipeline] powershell[microservice-helpers] Running PowerShell script
      [Pipeline] powershell[microservice-helpers] Running PowerShell script
      This is the info stream
      [Pipeline] }
      [Pipeline] // stage

      Notice that the verbose stream is not written to the console. I propose a new flag for the powershell step, which would allow user-selected streams (such as Verbose and Debug) to be output to console.

      To get these streams in powershell, it is generally only necessary to use the common parameters -Debug and -Verbose when calling the script. See this link for more information:

      https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-5.1

      Another way to trigger output of the verbose stream is to set $VerbosePreference = 'Continue' at a global level in the shell before running the actual script.
       

      See also this blog post on streams in powershell:

      https://blogs.technet.microsoft.com/heyscriptingguy/2014/03/30/understanding-streams-redirection-and-write-host-in-powershell/

       

            Unassigned Unassigned
            ftherien Francis Therien
            Votes:
            4 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: