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 created issue -
            dicomj23 Dicom J made changes -
            Field Original Value New Value
            Description Similar case to 
            [https://wiki.jenkins.io/display/JENKINS/Pipeline+CPS+method+mismatches#PipelineCPSmethodmismatches-Directinvocationofclosuresstoredinobjectfieldsormaps]

            But instead of Closure, but this time the method from loaded script is called, what could be simulated right now even in a single Jenkins file.
            {code:java}
            def scriptMethod() {
                println 'passed'
            }


            class Test {
              def fn
            }


            node {
                def object = new Test()
                object.fn = this.&scriptMethod
                object.fn.call()
            } {code}
            Got an exception:
            {code:java}
            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) {code}

            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).
            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.
            {code:java}
            def scriptMethod() {
                println 'passed'
            }


            class Test {
              def fn
            }


            node {
                def object = new Test()
                object.fn = this.&scriptMethod
                object.fn.call()
            } {code}
            Got an exception:
            {code:java}
            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) {code}
            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).
             
            jglick Jesse Glick made changes -
            Component/s groovy-plugin [ 15549 ]
            jglick Jesse Glick made changes -
            Assignee Andrew Bayer [ abayer ]
            jglick Jesse Glick made changes -
            Link This issue is caused by JENKINS-55764 [ JENKINS-55764 ]
            jglick Jesse Glick made changes -
            Link This issue is caused by JENKINS-31314 [ JENKINS-31314 ]

            People

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

              Dates

                Created:
                Updated: