jenkinsci / jenkinsci/workflow-cps-plugin
[JENKINS-40134] Groovy truth issue in Pipeline script
- Dominant language
- Java
- Stars
- 186
- Forks
- 213
- Avg merge
- 12h 12m
- Merged PRs (30d)
- 8
Description
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:
---
Originally reported by m_olk, imported from: Groovy truth issue in Pipeline script
Raw content of original issue
A Jenkins pipeline script combining two String values with a logical AND (&& operator) does not behave as expected:
'' && '' -> false
'a' && 'b' -> 'b'
'a' != '' && 'b != '' -> trueSo 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:
![]()
- environment:
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
1 attachment
- [Screen Shot 2016-11-30 at 22.58.37.png](https://issues.jenkins.io/secure/attachment/35048/Screen%20Shot%202016-11-30%20at%2022.58.37.png)
> 
Contributor guide
Research direction
No source file or test is named; start by reproducing the supplied Jenkins Pipeline example in workflow-cps-plugin and compare the reported String and boolean results. Done means the intended behavior for logical AND is agreed and the example no longer exhibits the unexpected result, with coverage for the shown cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- ci-cd, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100