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

Closures return early if they include a method call

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Won't Fix
    • Component/s: workflow-cps-plugin
    • Labels:
    • Environment:
      Jenkins 2.32.1, Pipeline Groovy 2.29, Groovy 2.4.7, latest Pipeline plugins (as of 03/23/17)
    • Similar Issues:

      Description

      Problem

      It seems that in a pipeline, Groovy closures are returned early if you call a method inside them. The closure then only returns the return value of the called method. I provided a minimal sample to reproduce the bug below.

      Steps to Reproduce

      • Execute the following code in a Jenkins pipeline
        class Foo {
            Closure<String> cl = { String a ->
                return "Say: ${this.bar(a)}"
            }
            String bar(String a) {
                return "Hello ${a}."
            }
        }
        Foo f = new Foo()
        String output = f.getCl()("World")
        echo(output)
        
      • It does not matter if the code is executed in the sandbox or not
      • The expected output, as tested with Groovy 2.4.7 locally, is:
        • Say: Hello World.
      • Jenkins however outputs:
        • Hello World.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              marbec Mark J. Becker
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: