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

Class members sometimes not visible: groovy global shared library

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • None

      This issue occured after upgrading the following pipeline-related plugins and dependencies:

      • Pipeline: API: 2.8 -> 2.20
      • Pipeline: Groovy: 2.24 -> 2.40
      • Pipeline: SCM Step: 2.3 -> 2.6
      • Pipeline: Shared Groovy Libraries: 2.5 -> 2.9
      • Pipeline: Step API: 2.7 -> 2.12
      • Pipeline: Supporting APIs: 2.12 -> 2.14
      • SCM API Plugin: 2.0.8 -> 2.2.2
      • Script Security Plugin: 1.25 -> 1.34
      • Structs Plugin: 1.5 -> 1.10

      After that in one of our Pipeline jobs Jenkins complained that one of our classes in the shared groovy library we use would not have a referenced member. The referenced member is defined in the base class.

      I've created a very small shared library which can be used to reproduce the issue. Please find it attached.

      For the job please use the following (or similar) code to reproduce the issue.

      @Library('cpsLibIssue')
      import issue.*
      // Add the following import and it'll work
      // import issue.DerivedClass
      
      // comment out the following line - and it'll work as well (even without the explicit import)
      def baseClass = new BaseClass(steps)
      new DerivedClass(steps).doSomething()

      If I explicitly import the DerivedClass the error will disappear.

      If I won't create an object of the BaseClass it'll disappear as well.

      One could get very frustrated because of this issue. It was hard to find, took me some hours. Hopefully it can be fixed easily as I can't tell when it will occur next time.

      The code for both classes looks like:

      package issue
      
      import org.jenkinsci.plugins.workflow.cps.DSL
      
      class DerivedClass extends BaseClass implements Serializable {
      
          DerivedClass(DSL steps) {
              super(steps)
          }
      
          def doSomething() {
              steps.echo "Won't work"
          }
      }
      package issue
      
      import org.jenkinsci.plugins.workflow.cps.DSL
      
      class BaseClass implements Serializable {
          DSL steps
      
          BaseClass(DSL steps) {
              this.steps = steps
          }
      }

            Unassigned Unassigned
            macdrega Joerg Schwaerzler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: