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

Class Inheritance does not work in Groovy CPS

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • workflow-cps-plugin
    • None
    • Jenkins 2.45
      Pipeline 2.5
      workflow-cps 2.25

      I'm trying to setup a reusable global pipeline library with several test tools with different parameters and experienced the following behaviour with this piece of code:

      node {
          BaseTool st = new MyTool()
          st.number = 1
          st.uid = 10
          st.name = "Joe"
      
          println(st.name)
          echo "foo " + st.displaySomething()
          println(st.displaySomething())
      }
      
      abstract class BaseTool implements Serializable {
          public String name
      
          public BaseTool() {}
      
          abstract void displaySomething()
      }
      
      class MyTool extends BaseTool {
          int number
          int uid
      
          public MyTool() {
              super()
          }
      
          void displaySomething() {
              echo "something"
              println(uid)
          }
      }
      

      I get the following output:

      [Pipeline] node
      Running on master in /var/lib/jenkins/jobs/AbstractTest/workspace
      [Pipeline] {
      [Pipeline] echo
      Joe
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: MyTool.echo() is applicable for argument types: (java.lang.String) values: [something]
      Possible solutions: each(groovy.lang.Closure), getAt(java.lang.String), wait(), any(), every(), dump()
      

      This means, i can't call any pipeline steps and so on from the implemented method.

            Unassigned Unassigned
            rpionke Raphael Pionke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: