-
Bug
-
Resolution: Unresolved
-
Trivial
-
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
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. |
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. |
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. |
Component/s | New: workflow-cps-plugin [ 21713 ] | |
Component/s | Original: pipeline [ 21692 ] |
Assignee | New: Xuezhong Yan [ jackyim ] |
Resolution | New: Cannot Reproduce [ 5 ] | |
Status | Original: Open [ 1 ] | New: Fixed but Unreleased [ 10203 ] |
Status | Original: Fixed but Unreleased [ 10203 ] | New: Closed [ 6 ] |
Comment | [ Cannot Reproduce on P4 Plugin 1.9.4, hence close this issue. ] |
Resolution | Original: Cannot Reproduce [ 5 ] | |
Status | Original: Closed [ 6 ] | New: Reopened [ 4 ] |