jenkinsci / jenkinsci/workflow-cps-plugin

[JENKINS-41422] Assignment in if statements does not work

Open
#1,269 0 comments 0 reactions 0 assignees View on GitHub
component:workflow-cps-plugin imported-jira-issue pipeline priority:minor resolution:unresolved
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


  • status: Open
  • priority: Minor
  • component(s): workflow-cps-plugin
  • label(s): complex-cps-code, pipeline, triaged-2018-11
  • resolution: Unresolved
  • votes: 1
  • watchers: 4
  • imported: 2025-12-07

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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.