[JIRA] (JENKINS-59674) Groovy .with {...} seems to need @NonCPS

2 views
Skip to first unread message

jvallon1@bloomberg.net (JIRA)

unread,
Oct 5, 2019, 12:51:06 AM10/5/19
to jenkinsc...@googlegroups.com
Justin Vallon created an issue
 
Jenkins / Bug JENKINS-59674
Groovy .with {...} seems to need @NonCPS
Issue Type: Bug Bug
Assignee: Unassigned
Components: workflow-cps-plugin
Created: 2019-10-05 04:50
Environment: Jenkins 2.198
workflow-cps ("Pipeline: Groovy") 2.74
Debian 9
OpenJDK 11.0.4
Labels: groovy cps
Priority: Minor Minor
Reporter: Justin Vallon

The following function demonstrates the problem:

Object func1() {
    Object m = [:];
    m.with { x = 1 };
    return m;
}
assert func1() == [ : ]; // wrong, should be [x:1]

This is supposed run the "x=1" in the context of m. However, func1() returns an empty map.

If func is marked @NonCPS, it returns map [x:1].

@NonCPS
Object func2() {
    Object m = [:];
    m.with { x = 1 };
    return m;
}
assert func2() == [ x:1 ];

Running these in a Jenkinsfile.  When run in the script console, the @NonCPS is not needed (behaves as expected).
My expectation is that func1 should work without needing a @NonCPS annotation.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages