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

String interpolation on an object with toString() silently skips the step

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None
    • Jenkins 2.89.4
      pipeline-model-api 1.2.7
      pipeline-model-definition 1.2.7

      This scripts works in the /script console:

      class Foo implements Serializable {
        public String toString() {
          return "Foo."
        }
      }
      
      def foo = new Foo()
      println("Class is: ${foo}") // Class is: Foo.
      

      This one instead skips the step and raises no error:

      class Foo implements Serializable {
          public String toString() {
              return "Foo."
          }
      }
      
      stage 'My stage', {
          def foo = new Foo()
          echo "Let's try to echo foo..."
          echo "Class is: ${foo}" 
          echo "Did we echo foo?"
      }
      

      Its output is:

      [Pipeline] stage
      [Pipeline] { (My stage)
      [Pipeline] echo
      Let's try to echo foo...
      [Pipeline] echo
      Did we echo foo?
      [Pipeline] }
      [Pipeline] // stage
      

      It's unclear how much is skipped, I had this inside a custom sh step that pushes Github hooks and the command was not executed as well.

      Calling .toString() works, but it should not be necessary. Also any kind of error should be raised if the step is not executed, rather than silently skipping it.

      If I remove the custom toString:

      class Foo implements Serializable {
      
      }
      
      stage 'My stage', {
          def foo = new Foo()
          echo "Let's try to echo foo..."
          echo "Class is: ${foo}" 
          echo "Did we echo foo?"
      }
      

      normal output is produced with the default toString:

      [Pipeline] { (My stage)
      [Pipeline] echo
      Let's try to echo foo...
      [Pipeline] echo
      Class is: Foo@4da69f18
      [Pipeline] echo
      Did we echo foo?
      [Pipeline] }
      [Pipeline] // stage
      

            Unassigned Unassigned
            giorgiosironi Giorgio Sironi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: