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

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

    XMLWordPrintable

Details

    Description

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

      Attachments

        Issue Links

          Activity

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

            dicomj23 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.
            jglick 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()}
            
            jglick 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()}
            dicomj23 Dicom J added a comment - same as  https://issues.jenkins-ci.org/browse/JENKINS-58407  
            dicomj23 Dicom J added a comment -

            cc: jglick

            dicomj23 Dicom J added a comment - cc: jglick

            People

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

              Dates

                Created:
                Updated: