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

10 views
Skip to first unread message

dicomj23@gmail.com (JIRA)

unread,
Dec 20, 2019, 4:55:04 AM12/20/19
to jenkinsc...@googlegroups.com
Dicom J created an issue
 
Jenkins / Bug JENKINS-60552
Fail to call a script method stored as a class attribute/field
Issue Type: Bug Bug
Assignee: Andrew Bayer
Components: groovy-plugin, workflow-cps-plugin
Created: 2019-12-20 09:54
Priority: Blocker Blocker
Reporter: Dicom J

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.

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

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

dicomj23@gmail.com (JIRA)

unread,
Dec 20, 2019, 4:55:05 AM12/20/19
to jenkinsc...@googlegroups.com
Dicom J updated an issue
Change By: Dicom J
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).
 

dicomj23@gmail.com (JIRA)

unread,
Dec 20, 2019, 4:56:02 AM12/20/19
to jenkinsc...@googlegroups.com

dicomj23@gmail.com (JIRA)

unread,
Dec 20, 2019, 5:43:01 AM12/20/19
to jenkinsc...@googlegroups.com

jglick@cloudbees.com (JIRA)

unread,
Dec 20, 2019, 10:19:03 AM12/20/19
to jenkinsc...@googlegroups.com
Jesse Glick assigned an issue to Unassigned
 
Change By: Jesse Glick
Assignee: Andrew Bayer

jglick@cloudbees.com (JIRA)

unread,
Dec 20, 2019, 10:19:03 AM12/20/19
to jenkinsc...@googlegroups.com

jglick@cloudbees.com (JIRA)

unread,
Dec 20, 2019, 10:22:01 AM12/20/19
to jenkinsc...@googlegroups.com
Jesse Glick commented on Bug JENKINS-60552
 
Re: Fail to call a script method stored as a class attribute/field

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@gmail.com (JIRA)

unread,
Dec 20, 2019, 10:49:02 AM12/20/19
to jenkinsc...@googlegroups.com
Dicom J commented on Bug JENKINS-60552

Thanks Jesse Glick, 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.

Reply all
Reply to author
Forward
0 new messages