This issue is archived. You can view it, but you can't modify it. Learn more

ExportXMLWordPrintable

      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.

            Assignee:
            Xuezhong Yan
            Reporter:
            Xuezhong Yan
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: