Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-59674

Groovy .with {...} seems to need @NonCPS

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: workflow-cps-plugin
    • Labels:
    • Environment:
      Jenkins 2.198
      workflow-cps ("Pipeline: Groovy") 2.74
      Debian 9
      OpenJDK 11.0.4
    • Similar Issues:

      Description

      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.

        Attachments

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              Unassigned
              Reporter:
              vallon Justin Vallon
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: