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

Global variables starting with capital letter regression

XMLWordPrintable

      Problem

      Calling a function like `Myvariable.myFunctionName()` from a global library returns the following error;

      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified method java.lang.Class myFunctionName
      

      This only happens when calling global variables beginning with a capital letter.

      Downgrading the workflow-cps-global-lib plugin to v2.0 results in the error going away. Upgrading to v2.1 makes the error appear.

      From my point of view this is a regression between v2.0 and v2.1.

      Am I not supposed to create global variables starting with a capital letter? This represents a breaking change in some of my global library code.

      Steps to reproduce

      1. Setup a global library like;

      # directory structure
      +- vars
       |   +- one.groovy 
       |   +- Two.groovy 
      
      # in vars/one.groovy
      def call() {
        echo "in one()"
      }
      
      def fn() {
        echo "In one.fn()"
      }
      
      # in vars/Two.groovy
      def call() {
        echo "In Two()"
      }
      
      def fn() {
        echo "In Two.fn()"
      }
      

      2. Load the global library into jenkins (git push)

      3. Create a pipeline job with the following pipeline script

      one()
      one.fn()
      
      Two()
      Two.fn()
      
      Expected Output
      [Pipeline] echo
      in one()
      [Pipeline] echo
      In one.fn()
      [Pipeline] echo
      In Two()
      [Pipeline] echo
      In Two.fn()
      
      Actual Output
      in one()
      [Pipeline] echo
      In one.fn()
      [Pipeline] echo
      In Two()
      [Pipeline] End of Pipeline
      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified method java.lang.Class fn
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:113)
      	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
      
              [... truncated - full stack trace attached to ticket ...]
      

            jglick Jesse Glick
            philgrayson Phil Grayson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: