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

Pipeline powershell step hangs if a function is called from powershell workflow

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • durable-task-plugin
    • Windows Server 2012 R2 64 Bit, Jenkins 2.138.2, Pipeline: Nodes and Processes 2.26, Durable Task Plugin 1.27

      I have a Jenkins pipeline that contains a step 'powershell'. From the powershell script, I want to execute some actions in parallel. powershell has the Workflow concept for this (not to confuse with Jenkins workflow).

      If I execute the script from the powershell console, everything works OK. If I execute the same script from within a Jenkins pipeline, it hangs. The only output I see is:

      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (test)
      [Pipeline] powershell

       

      The Jenkins pipeline script is as follows (it contains some commented lines to make changes easy, see below):

      node('myNode') {
          stage('test') {
              powershell '''
              function execFunc($n) {
                  Write-Output "I am $n"
              }
              
              Workflow execInParallel() {
                  foreach -parallel ($n in 1,2) {
                      execFunc $n
                      #Write-Output "I am $n"   # Change 1
                  }
              }
              
              function execSequentially() {
                  foreach ($n in 1,2) {
                      execFunc $n
                  }
              }
              
              execInParallel
              #execSequentially     # Change 2
              '''
          }
      }

      The script as it is hangs.

      However, if I make the following changes (independently, i.e. each change on its own is sufficient), it does not hang:

      1. If I "inline" the function execFunc, i.e. activate the line 'Change 1' and comment the line above (the call to execFunc), the script does not hang
      2. If I replace the parallel execution with the sequential one, i.e. activate the line 'Change 2' and comment the line above (call to 'execInParallel'), then the script does not hang.

      The hanging only occurs if I use the powershell workflow and call a function from within it.

      In an earlier version of the "Pipeline: Nodes and Processes" plugin (I think, it was 2.17, but I'm not sure), everything worked OK.

      The job itself is named "zzzTestPowershellWorkflow" I.e. the name does not contain any "bad" characters (spaces or the like).

            Unassigned Unassigned
            fml2 Al Le
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: