-
Bug
-
Resolution: Duplicate
-
Major
-
None
-
Jenins 2.19.3 and Pipeline 2.4
We had this issue inside of a Global Library but are able to reproduce it with a simple pipeline job.
Steps to Reproduce:
- Create a pipeline job with the following script:
//Not the real function but good enough to demonstrate problem def getSlaves() { [ [name: 'good', isOnline: true ], [name: 'bad' , isOnline: false] ]} @NonCPS def verifyAllSlavesOnline() { def errorList = [] for (def slave in getSlaves()) { if(!slave.isOnline) { errorList << "Slave is off line: ${slave.name}" } } errorList } println verifyAllSlavesOnline()
- Expected output of println is
[Slave is off line: bad]
but instead with get:
[{name=good, isOnline=true}, {name=bad, isOnline=false}]
Essentially the return value from getSlaves() is being returned instead of the content of errorList.
In our case, the use of @NonCPS here was in error because the original code that required it had been refactored into the getSlaves() function. So we were able to solve the problem with this rewrite:
//Not the real function but good enough to demonstrate problem def getSlaves() { [ [name: 'good', isOnline: true ], [name: 'bad' , isOnline: false] ]} def verifyAllSlavesOnline() { def errorList = [] def slaves = getDrSlaves() for (def s = 0; s < slaves.size; s++ ) { def slave = slaves[s] if(!slave.isOnline) { errorList << "Slave is off line: ${slave.name}" } } errorList } println verifyAllSlavesOnline()
The above produces the expected output.
Decorating the corrected function with @NonCPS again causes it to return the same wrong results!
- duplicates
-
JENKINS-26481 Mishandling of binary methods accepting Closure
- Resolved