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

Result of assignment expression is null rather than assigned value

    Details

    • Similar Issues:

      Description

      Hello Guys,

      I found some weird behavior difference in executing the same groovy logic in pipeline from the original groovy 2.4.12 (used in the latest LTS Jenkins by default).

      The next logic is working in different ways for pipeline and script console:

      def b = 3
      def a = b = 4
      print("${a} ${b}")
      
      • Groovy console print output: "4 4"
      • Pipeline echo output: "null 4"

      Who can tell why? I just can't catch the difference.

        Attachments

          Activity

          Hide
          sparshev Sergei Parshev added a comment -

          Jesse Glick maybe you can help with this question?

          Show
          sparshev Sergei Parshev added a comment - Jesse Glick maybe you can help with this question?
          Hide
          jglick Jesse Glick added a comment -
          Show
          jglick Jesse Glick added a comment - A bug in https://github.com/cloudbees/groovy-cps presumably.
          Hide
          sparshev Sergei Parshev added a comment -

          Oh, I thought it's just a "feature" in realization like "don't use `.each`" and stuff... Ok, good to know, thank you)

          Show
          sparshev Sergei Parshev added a comment - Oh, I thought it's just a "feature" in realization like "don't use `.each`" and stuff... Ok, good to know, thank you)
          Hide
          sparshev Sergei Parshev added a comment - - edited

          Yeah, I added a test to groovy-cps:

          @Test
          void justatest() {
              assert evalCPS('''
                  def a = 3;
                  def b = 4;
                  a = b = 6;
                  return "${a}, ${b}";
              ''')=="6, 6";
          }
          

          and it's failed:

          [ERROR] Failures:
          [ERROR]   CpsTransformerTest.justatest:50->AbstractGroovyCpsTest.evalCPS:50 assert resultInCps==sh.evaluate(script)
                 |          | |  |        |
                 null, 6    | |  6, 6
                            | |                       def a = 3;
                            | |                       def b = 4;
                            | |                       a = b = 6;
                            | |                       return "${a}, ${b}";
                            | |
                            | groovy.lang.GroovyShell@6ae42248
                            false
          
          Show
          sparshev Sergei Parshev added a comment - - edited Yeah, I added a test to groovy-cps: @Test void justatest() { assert evalCPS(''' def a = 3; def b = 4; a = b = 6; return "${a}, ${b}" ; ''')== "6, 6" ; } and it's failed: [ERROR] Failures: [ERROR] CpsTransformerTest.justatest:50->AbstractGroovyCpsTest.evalCPS:50 assert resultInCps==sh.evaluate(script) | | | | | null, 6 | | 6, 6 | | def a = 3; | | def b = 4; | | a = b = 6; | | return "${a}, ${b}"; | | | groovy.lang.GroovyShell@6ae42248 false

            People

            • Assignee:
              Unassigned
              Reporter:
              sparshev Sergei Parshev
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: