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

Global variables starting with capital letter regression

      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 ...]
      

          [JENKINS-38281] Global variables starting with capital letter regression

          Phil Grayson created issue -
          Phil Grayson made changes -
          Description Original: h3. Problem

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

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

          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

          h3. Steps to reproduce
          1. Setup a global library like;

          {code:java}
          # directory structure
          +- vars
           | +- one.groovy
           | +- Two.groovy
          {code}

          {code:java}
          # in vars/one.groovy
          def call() {
            echo "in one()"
          }

          def fn() {
            echo "In one.fn()"
          }
          {code}

          {code:java}
          # in vars/Two.groovy
          def call() {
            echo "In Two()"
          }

          def fn() {
            echo "In Two.fn()"
          }
          {code}

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

          3. Create a pipeline job with the following pipeline script

          {code:java}
          one()
          one.fn()

          Two()
          Two.fn()
          {code}


          h5. Expected Output
          {code}
          [Pipeline] echo
          in one()
          [Pipeline] echo
          In one.fn()
          [Pipeline] echo
          In Two()
          [Pipeline] echo
          In Two.fn()
          {code}

          h5. Actual Output

          {code}
          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 ...]
          {code}


          New: h3. Problem

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

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

          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.

          h3. Steps to reproduce
          1. Setup a global library like;

          {code:java}
          # directory structure
          +- vars
           | +- one.groovy
           | +- Two.groovy
          {code}

          {code:java}
          # in vars/one.groovy
          def call() {
            echo "in one()"
          }

          def fn() {
            echo "In one.fn()"
          }
          {code}

          {code:java}
          # in vars/Two.groovy
          def call() {
            echo "In Two()"
          }

          def fn() {
            echo "In Two.fn()"
          }
          {code}

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

          3. Create a pipeline job with the following pipeline script

          {code:java}
          one()
          one.fn()

          Two()
          Two.fn()
          {code}


          h5. Expected Output
          {code}
          [Pipeline] echo
          in one()
          [Pipeline] echo
          In one.fn()
          [Pipeline] echo
          In Two()
          [Pipeline] echo
          In Two.fn()
          {code}

          h5. Actual Output

          {code}
          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 ...]
          {code}


          Jesse Glick made changes -
          Link New: This issue is duplicated by JENKINS-36673 [ JENKINS-36673 ]
          Jesse Glick made changes -
          Remote Link New: This issue links to "workflow-step-api PR 9 (Web Link)" [ 14923 ]
          Jesse Glick made changes -
          Labels New: robustness
          Vivek Pandey made changes -
          Labels Original: robustness New: robustness triaged-2018-11

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

              Created:
              Updated: