-
Bug
-
Resolution: Unresolved
-
Minor
-
Jenkins 2.9, Docker container, Oracle OpenJDK 1.8.0_91-8u91-b14-1~bpo8+1-b14 64-Bit Server VM, Linux 4.4.0-47-generic
A Jenkins pipeline script combining two String values with a logical AND (&& operator) does not behave as expected:
'' && '' -> false 'a' && 'b' -> 'b' 'a' != '' && 'b != '' -> true
So when combining two non empty values the result is not of type boolean but the second value of type String.
The following script demonstrates this behavior:
node { def doit = { String s1, String s2 -> def p = { v -> "'$v' (${v.class})" } echo "s1 = ${p s1}, s2 = ${p s2}" echo "s1 && s2 = ${p s1 && s2}" echo "s1 != '' && s2 != '' = ${p s1 != '' && s2 != ''}" } doit '', '' doit 'foo', 'bar' }
Console of an example run in my environment:
[JENKINS-40134] Groovy truth issue in Pipeline script
Summary | Original: Groovy truth issue in parameterized Pipeline script | New: Groovy truth issue in Pipeline script |
Description |
Original:
A Jenkins pipeline script combining two {{String}} values with a logical AND ({{&&}} operator) does not behave as expected: {code} '' && '' -> false 'a' && 'b' -> 'b' 'a' != '' && 'b != ''' -> true {code} So when combining two non empty values the result is not of type {{boolean}} but the second value of type {{String}}. The following script demonstrates this behavior: {code} node { def doit = { String s1, String s2 -> def p = { v -> "'$v' (${v.class})" } echo "s1 = ${p s1}, s2 = ${p s2}" echo "s1 && s2 = ${p s1 && s2}" echo "s1 != '' && s2 != '' = ${p s1 != '' && s2 != ''}" } doit '', '' doit 'foo', 'bar' } {code} Console of an example run in my environment: !Screen Shot 2016-11-30 at 22.58.37.png! |
New:
A Jenkins pipeline script combining two {{String}} values with a logical AND ({{&&}} operator) does not behave as expected: {code} '' && '' -> false 'a' && 'b' -> 'b' 'a' != '' && 'b != '' -> true {code} So when combining two non empty values the result is not of type {{boolean}} but the second value of type {{String}}. The following script demonstrates this behavior: {code} node { def doit = { String s1, String s2 -> def p = { v -> "'$v' (${v.class})" } echo "s1 = ${p s1}, s2 = ${p s2}" echo "s1 && s2 = ${p s1 && s2}" echo "s1 != '' && s2 != '' = ${p s1 != '' && s2 != ''}" } doit '', '' doit 'foo', 'bar' } {code} Console of an example run in my environment: !Screen Shot 2016-11-30 at 22.58.37.png! |
Component/s | New: workflow-cps-plugin [ 21713 ] | |
Component/s | Original: pipeline [ 21692 ] |
Labels | Original: pipeline | New: complex-cps-code pipeline triaged-2018-11 |