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

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

XMLWordPrintable

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

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

              Created:
              Updated: