jenkinsci / jenkinsci/workflow-cps-plugin
[JENKINS-41422] Assignment in if statements does not work
- Dominant language
- Java
- Stars
- 186
- Forks
- 213
- Avg merge
- 12h 12m
- Merged PRs (30d)
- 8
Description
The following fails in pipeline scripts (the if statement always evaluates to false)
def getStatus(){
// ....
"Ready"
}//....
def acceptedStatuses = ["Ready", "Updated", "Failed" ]
def status
if(acceptedStatuses.contains((status = getStatus()))){
// never called
}
---
Originally reported by zhelyan, imported from: Assignment in if statements does not work
Raw content of original issue
The following fails in pipeline scripts (the if statement always evaluates to false)
def getStatus(){
// ....
"Ready"
}//....
def acceptedStatuses = ["Ready", "Updated", "Failed" ]
def status
if(acceptedStatuses.contains((status = getStatus()))){
// never called
}
environment
```
Jenkins 2.42
Pipeline 2.4
workflow-cps 2.24
```
Contributor guide
Research direction
Start by reproducing the supplied pipeline script in the workflow-cps plugin with the listed Jenkins, Pipeline, and workflow-cps versions. Trace how the CPS interpreter handles the assignment inside contains; done means getStatus assigns "Ready" to status and the if body executes for an accepted status.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- ci-cd, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100