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

Groovy Pipeline Use an assignment within a "while" condition error

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Trivial Trivial
    • workflow-cps-plugin
    • None
    • Jenkins version: 2.73.1
      Pipeline: Shared Groovy Libraries 2.9

      I use @Grab annotation to load Java jar from maven center. Then I wrote java language in my groovy file.  I have some code pieces like the following:

      while ((read = fInputStream.read(buffer)) != -1) {
          fOptStream.write(buffer, 0, read);              
      }
      

      I read a file and then save to another location, if the file ends, then return -1.

      This code works fine on my local groovy 2.4.12. but when I execute the groovy file in Jenkins. I got endless loop in while. I printed the log and found the read value is correct(-1), but it won't break the while loop. It seems that the return value is the result of the assignment. So I modify the code as follows:

      read = fInputStream.read(buffer)
      while (read != -1) {
          fOptStream.write(buffer, 0, read);    
          read = fInputStream.read(buffer)          
      }

      It can work normally.

      I guess there might be something wrong in Jenkins embedded groovy engine. 

      It doesn't support an assignment within a while condition.

          [JENKINS-47014] Groovy Pipeline Use an assignment within a "while" condition error

          Xuezhong Yan created issue -
          Xuezhong Yan made changes -
          Description New: I use @Grab annotation to load Java jar from maven center. Then I wrote java language in my groovy file.  I have some code pieces like the following:
          {code:java}
          while ((read = fInputStream.read(buffer)) != -1) {
              fOptStream.write(buffer, 0, read);              
          }
          {code}
          I read a file and then save to another location, if the file ends, then return -1.

          This code works fine on my local groovy 2.4.12. but when I execute the groovy file in Jenkins. I got endless loop in while. I printed the log and found the read value is correct(-1), but it won't break the while loop.  So I modify the code as follows:
          {code:java}
          read = fInputStream.read(buffer)
          while (read != -1) {
              fOptStream.write(buffer, 0, read);              
          }{code}
          It can work normally.

          I guess there might be something wrong in Jenkins embedded groovy engine.
          Xuezhong Yan made changes -
          Description Original: I use @Grab annotation to load Java jar from maven center. Then I wrote java language in my groovy file.  I have some code pieces like the following:
          {code:java}
          while ((read = fInputStream.read(buffer)) != -1) {
              fOptStream.write(buffer, 0, read);              
          }
          {code}
          I read a file and then save to another location, if the file ends, then return -1.

          This code works fine on my local groovy 2.4.12. but when I execute the groovy file in Jenkins. I got endless loop in while. I printed the log and found the read value is correct(-1), but it won't break the while loop.  So I modify the code as follows:
          {code:java}
          read = fInputStream.read(buffer)
          while (read != -1) {
              fOptStream.write(buffer, 0, read);              
          }{code}
          It can work normally.

          I guess there might be something wrong in Jenkins embedded groovy engine.
          New: I use @Grab annotation to load Java jar from maven center. Then I wrote java language in my groovy file.  I have some code pieces like the following:
          {code:java}
          while ((read = fInputStream.read(buffer)) != -1) {
              fOptStream.write(buffer, 0, read);              
          }
          {code}
          I read a file and then save to another location, if the file ends, then return -1.

          This code works fine on my local groovy 2.4.12. but when I execute the groovy file in Jenkins. I got endless loop in while. I printed the log and found the read value is correct(-1), but it won't break the while loop. It seems that the return value is the result of the assignment. So I modify the code as follows:
          {code:java}
          read = fInputStream.read(buffer)
          while (read != -1) {
              fOptStream.write(buffer, 0, read);              
          }{code}
          It can work normally.

          I guess there might be something wrong in Jenkins embedded groovy engine. 

          It doesn't support an assignment within a while condition.
          Xuezhong Yan made changes -
          Description Original: I use @Grab annotation to load Java jar from maven center. Then I wrote java language in my groovy file.  I have some code pieces like the following:
          {code:java}
          while ((read = fInputStream.read(buffer)) != -1) {
              fOptStream.write(buffer, 0, read);              
          }
          {code}
          I read a file and then save to another location, if the file ends, then return -1.

          This code works fine on my local groovy 2.4.12. but when I execute the groovy file in Jenkins. I got endless loop in while. I printed the log and found the read value is correct(-1), but it won't break the while loop. It seems that the return value is the result of the assignment. So I modify the code as follows:
          {code:java}
          read = fInputStream.read(buffer)
          while (read != -1) {
              fOptStream.write(buffer, 0, read);              
          }{code}
          It can work normally.

          I guess there might be something wrong in Jenkins embedded groovy engine. 

          It doesn't support an assignment within a while condition.
          New: I use @Grab annotation to load Java jar from maven center. Then I wrote java language in my groovy file.  I have some code pieces like the following:
          {code:java}
          while ((read = fInputStream.read(buffer)) != -1) {
              fOptStream.write(buffer, 0, read);              
          }
          {code}
          I read a file and then save to another location, if the file ends, then return -1.

          This code works fine on my local groovy 2.4.12. but when I execute the groovy file in Jenkins. I got endless loop in while. I printed the log and found the read value is correct(-1), but it won't break the while loop. It seems that the return value is the result of the assignment. So I modify the code as follows:
          {code:java}
          read = fInputStream.read(buffer)
          while (read != -1) {
              fOptStream.write(buffer, 0, read);    
              read = fInputStream.read(buffer)          
          }{code}
          It can work normally.

          I guess there might be something wrong in Jenkins embedded groovy engine. 

          It doesn't support an assignment within a while condition.
          Andrew Bayer made changes -
          Component/s New: workflow-cps-plugin [ 21713 ]
          Component/s Original: pipeline [ 21692 ]
          Xuezhong Yan made changes -
          Assignee New: Xuezhong Yan [ jackyim ]
          Xuezhong Yan made changes -
          Resolution New: Cannot Reproduce [ 5 ]
          Status Original: Open [ 1 ] New: Fixed but Unreleased [ 10203 ]
          Xuezhong Yan made changes -
          Status Original: Fixed but Unreleased [ 10203 ] New: Closed [ 6 ]
          Xuezhong Yan made changes -
          Comment [ Cannot Reproduce on P4 Plugin 1.9.4, hence close this issue. ]
          Xuezhong Yan made changes -
          Resolution Original: Cannot Reproduce [ 5 ]
          Status Original: Closed [ 6 ] New: Reopened [ 4 ]
          Xuezhong Yan made changes -
          Priority Original: Minor [ 4 ] New: Trivial [ 5 ]

            jackyim Xuezhong Yan
            jackyim Xuezhong Yan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: