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

Fail to call a script method stored as a class attribute/field

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Blocker Blocker
    • workflow-cps-plugin
    • None

      Similar case to 
      https://wiki.jenkins.io/display/JENKINS/Pipeline+CPS+method+mismatches#PipelineCPSmethodmismatches-Directinvocationofclosuresstoredinobjectfieldsormaps

      But instead of Closure, this time the method from loaded script is called, what could be simulated right now even in a single Jenkins file.

      def scriptMethod() {
          println 'passed'
      }
      
      
      class Test {
        def fn
      }
      
      
      node {
          def object = new Test()
          object.fn = this.&scriptMethod
          object.fn.call()
      } 

      Got an exception:

      java.lang.IllegalStateException: expected to call org.codehaus.groovy.runtime.MethodClosure.call but wound up catching WorkflowScript.scriptMethod; see: https://jenkins.io/redirect/pipe
      line-cps-method-mismatches/
      at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService.handleMismatch(CpsVmExecutorService.java:123) at com.cloudbees.groovy.cps.impl.CpsCallableInvocation.checkMismatch(CpsCallableInvocation.java:98)  

      btw, Closure case works fine now. But this is critical as it doesn't allow to break a single Jenkinsfile into a couple of smaller modules (scripts).
       

          [JENKINS-60552] Fail to call a script method stored as a class attribute/field

          Dicom J added a comment -

          cc: jglick

          Dicom J added a comment - cc: jglick

          Dicom J added a comment -

          Dicom J added a comment - same as  https://issues.jenkins-ci.org/browse/JENKINS-58407  

          Jesse Glick added a comment -

          Would only be a warning, but I suppose you are using JFR in which case it is an error due to JENKINS-55764.

          Workaround (untested): just avoid method references or other Groovy exotica:

          object.fn = {-> scriptMethod()}
          

          Jesse Glick added a comment - Would only be a warning, but I suppose you are using JFR in which case it is an error due to JENKINS-55764 . Workaround (untested): just avoid method references or other Groovy exotica: object.fn = {-> scriptMethod()}

          Dicom J added a comment -

          Thanks jglick, I really appreciate your replies! Yes, workaround would work. Regarding JFR - here, you're right as well. Actually we use both, JFR to develop pipelines locally and Jenkins run production mode. So we try to keep codebase same for JFR and regular Jenkins, IOW we try to avoid "if (JFR)" statements.

          Dicom J added a comment - Thanks jglick , I really appreciate your replies! Yes, workaround would work. Regarding JFR - here, you're right as well. Actually we use both, JFR to develop pipelines locally and Jenkins run production mode. So we try to keep codebase same for JFR and regular Jenkins, IOW we try to avoid "if (JFR)" statements.

            Unassigned Unassigned
            dicomj23 Dicom J
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: