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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: durable-task-plugin
    • Environment:
      Windows Server 2012 R2 64 Bit, Jenkins 2.138.2, Pipeline: Nodes and Processes 2.26, Durable Task Plugin 1.27
    • Similar Issues:

      Description

      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).

        Attachments

          Activity

          fml2 Al Le created issue -
          fml2 Al Le made changes -
          Field Original Value New Value
          Environment Windows, Jenkins 2.138.2, Pipeline: Nodes and Processes 2.26 Windows Server 2012 R2 64 Bit, Jenkins 2.138.2, Pipeline: Nodes and Processes 2.26
          fml2 Al Le made changes -
          Description 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):
          {code:java}
          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
                  '''
              }
          }{code}
          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:
           # 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
           # 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.
          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:
          {code:java}
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (test)
          [Pipeline] powershell{code}

            

          The Jenkins pipeline script is as follows (it contains some commented lines to make changes easy, see below):
          {code:java}
          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
                  '''
              }
          }{code}
          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:
           # 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
           # 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.
          fml2 Al Le made changes -
          Description 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:
          {code:java}
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (test)
          [Pipeline] powershell{code}

            

          The Jenkins pipeline script is as follows (it contains some commented lines to make changes easy, see below):
          {code:java}
          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
                  '''
              }
          }{code}
          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:
           # 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
           # 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.
          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:
          {code:java}
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (test)
          [Pipeline] powershell{code}
           

          The Jenkins pipeline script is as follows (it contains some commented lines to make changes easy, see below):
          {code:java}
          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
                  '''
              }
          }{code}
          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:
           # 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
           # 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).
          fml2 Al Le made changes -
          Environment Windows Server 2012 R2 64 Bit, Jenkins 2.138.2, Pipeline: Nodes and Processes 2.26 Windows Server 2012 R2 64 Bit, Jenkins 2.138.2, Pipeline: Nodes and Processes 2.26, Durable Task Plugin 1.27
          oleg_nenashev Oleg Nenashev made changes -
          Component/s powershell-plugin [ 16044 ]
          Component/s pipeline-library [ 23622 ]
          Key INFRA-1850 JENKINS-54618
          Workflow classic default workflow [ 232756 ] JNJira + In-Review [ 232812 ]
          Project Infrastructure [ 10301 ] Jenkins [ 10172 ]
          oleg_nenashev Oleg Nenashev made changes -
          Assignee R. Tyler Croy [ rtyler ]
          duemir Denys Digtiar made changes -
          Component/s durable-task-plugin [ 18622 ]
          Component/s powershell-plugin [ 16044 ]
          Hide
          duemir Denys Digtiar added a comment -

          Changed the component to durable-task since that is where powershell step resides.

          Show
          duemir Denys Digtiar added a comment - Changed the component to durable-task since that is where powershell step resides.

            People

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

              Dates

              Created:
              Updated: