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

Metaprogramming with InvokerHelper and MethodMissing triggers CPS MisMatch log

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • workflow-cps-plugin
    • None
    • workflow-cps:2.7.1
    • workflow-cps 2.73

      I currently work on a plugin ([Templating Engine Plugin|https://plugins.jenkins.io/templating-engine]) that relies on being able to leverage metaprogramming techniques such as using snippets like:

      InvokerHelper.getMetaClass(impl).invokeMethod(impl, methodName, args)
      

      or methodMissing to control program flow. 

       

      The introduction of logging CPS mismatched method names has resulted in continuously logging these occurrences. 

       

      Is there a way to work around the CPS mismatch logs for instances such as leveraging methodMissing or the InvokerHelper to dynamically execute methods? 

       

      methodMissing log:

      expected to call org.boozallen.plugins.jte.binding.injectors.StepWrapper.doThing but wound up catching org.boozallen.plugins.jte.binding.injectors.StepWrapper.methodMissing; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/
      expected to call org.boozallen.plugins.jte.hooks.Hooks.invoke but wound up catching script15632181891161818312862.call; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/

      InvokerHelper log:

      expected to call groovy.lang.ExpandoMetaClass.invokeMethod but wound up catching script1563218188258613791966.doThing; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/
      

       

      Simplest example to reproduce: 

       

      import org.codehaus.groovy.runtime.InvokerHelper
      c = {
          println "doing a thing"
      }
      InvokerHelper.getMetaClass(c).invokeMethod(c, "call", null)
      

       

          [JENKINS-58501] Metaprogramming with InvokerHelper and MethodMissing triggers CPS MisMatch log

          Steven Terrana added a comment - - edited

          I have implemented an approach to solving this problem and opened a pull request: 

          https://github.com/jenkinsci/workflow-cps-plugin/pull/305

           

          cc: jglick abayer

          Steven Terrana added a comment - - edited I have implemented an approach to solving this problem and opened a pull request:  https://github.com/jenkinsci/workflow-cps-plugin/pull/305   cc: jglick abayer

          Jesse Glick added a comment -

          With workflow-cps #306, probably falls on me or dnusbaum to play with a groovy-cps patch that would resolve the issue.

          One thing I should have done initially, but neglected to, was write unit tests in groovy-cps for this. Quicker to iterate than the full functional tests in workflow-cps, though we need at least some of those as well, since “things happen” when a library is being used in a complex context.

          Jesse Glick added a comment - With workflow-cps #306, probably falls on me or dnusbaum to play with a groovy-cps patch that would resolve the issue. One thing I should have done initially, but neglected to, was write unit tests in groovy-cps for this. Quicker to iterate than the full functional tests in workflow-cps , though we need at least some of those as well, since “things happen” when a library is being used in a complex context.

          Hey @jglick, i attempted a patch at this in groovy-cps and opened a PR.

          https://github.com/cloudbees/groovy-cps/pull/99

          Steven Terrana added a comment - Hey @jglick, i attempted a patch at this in groovy-cps and opened a PR. https://github.com/cloudbees/groovy-cps/pull/99

          Devin Nusbaum added a comment -

          A fix for this issue was just released in version 2.73 of Pipeline: Groovy Plugin.

          Devin Nusbaum added a comment - A fix for this issue was just released in version 2.73 of Pipeline: Groovy Plugin.

            sterrana Steven Terrana
            sterrana Steven Terrana
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: