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

Library class constructor error

XMLWordPrintable

      If there is a class in a library as well as some vars and the class's constructor tries to a var from the same library the new()'s result will be the var's result and not a class of the requested type.

       

      Sample code:

      src/com/test/X.groovy:

      package com.test
      public final class X {
          public final String result
          public X(def steps) {
              if (steps.y())
                  result = 'y returned TRUE'
             else
                  result = 'y returned FALSE'
          }
      }
      

       

      vars/y.groovy:

      def call() {
          return false
      }
      

       

      Jenkinsfile:

      lib = library 'testLib'
      x = lib.com.test.X(this)
      echo "x = $x"
      echo "result = ${x.result}"
      

       

      If testLib is set to contain the above code and the Jenkinsfile executed, then it will print:

      x = false

      and throw an exception:

      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such field found: field java.lang.Boolean result

       

      Calling into vars from other class methods seems to work fine.

            Unassigned Unassigned
            szabi_tolnai Szabolcs Tolnai
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: