• Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • workflow-cps-plugin
    • None

      Executing the following code as pipeline script (in a global library or after allowing Eval.x in the Sandbox):

      class Test {
          String testeval() {
              return Eval.x(this, '"${x.a()}-${x.b()}-${x.c()}"')
          }
          String a() {
              return "a"
          }
          String b() {
              return "b"
          }
          String c() {
              return "c"
          }
      }
      echo new Test().testeval()
      

      prints only "a" instead of the expected "a-b-c"

          [JENKINS-40591] Eval.x returns after the first method

          Hans Schulz added a comment - - edited

          I also found that

          class Test {
              def test = "${-> a()}-${-> b()}-${-> c()}"
              String testeval() {
                  return test.toString()
              }
              String a() {
                  return "a"
              }
              String b() {
                  return "b"
              }
              String c() {
                  return "c"
              }
          }
          echo new Test().testeval()
          

          does the same thing and

          class Test {
              def test = "${a()}-${b()}-${c()}"
              String testeval() {
                  return test.toString()
              }
              String a() {
                  return "a"
              }
              String b() {
                  return "b"
              }
              String c() {
                  return "c"
              }
          }
          echo new Test().testeval()
          

          results in a CpsCallableInvocation due to JENKINS-26313. This is fixable by annotating a() b() and c() with @NonCPS (and will return a-b-c then), but that really limits the usability.

          Hans Schulz added a comment - - edited I also found that class Test { def test = "${-> a()}-${-> b()}-${-> c()}" String testeval() { return test.toString() } String a() { return "a" } String b() { return "b" } String c() { return "c" } } echo new Test().testeval() does the same thing and class Test { def test = "${a()}-${b()}-${c()}" String testeval() { return test.toString() } String a() { return "a" } String b() { return "b" } String c() { return "c" } } echo new Test().testeval() results in a CpsCallableInvocation due to JENKINS-26313 . This is fixable by annotating a() b() and c() with @NonCPS (and will return a-b-c then), but that really limits the usability.

            Unassigned Unassigned
            schulzha Hans Schulz
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: