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

Passing method invocation as another method input default value breaks the second method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • workflow-cps-plugin
    • None
    • Jenkins 2.170, workflow-cps-plugin 2.65

       

      String test() {
          println("test")
          return "12345"
      }
      
      def testtest(String b = test()) {
          println("testtest")
      }
      
      testtest()
      println ("END")

       

      This script produces the following:

       

      [Pipeline] Start of Pipeline
      [Pipeline] echo
      test
      [Pipeline] echo
      END
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

       

      the  ' println("testtest")' is not invoked. Adding @NonCPS annotation is the available workaround:

       

      @NonCPS
      String test() {
          println("test")
          return "12345"
      }
      
      def testtest(String b = test()) {
          println("testtest")
      }
      
      testtest()
      println ("END")
      

       

      produces:

       

      [Pipeline] Start of Pipeline (hide)
      [Pipeline] echo
      test
      [Pipeline] echo
      testtest
      [Pipeline] echo
      END
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

      This doesn't look like a regression - it's reproduced in older versions as well.

            Unassigned Unassigned
            mooncrosser Grigor Lechev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: