define method in shared library:

      int getValue() {
          int i = 1
          i = ++i
      }
       
      

       throw exception:

       Caused by: hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: com.cloudbees.groovy.cps.Builder.prefixInc() is applicable for argument types: (java.lang.Integer, com.cloudbees.groovy.cps.impl.FunctionCallBlock) values: [83, com.cloudbees.groovy.cps.impl.FunctionCallBlock@66ea8f12]
       Possible solutions: prefixInc(int, com.cloudbees.groovy.cps.LValueBlock), prefixDec(int, com.cloudbees.groovy.cps.LValueBlock), postfixInc(int, com.cloudbees.groovy.cps.LValueBlock)
       at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)

      If I change

      ++i 

      to

       i + 1

      , all work perfectly.

          [JENKINS-44616] groovy increment does not work

          Bassam Khouri added a comment -

          I'm just commenting for the sake of commenting.  I'm not an expert in groovy but it's the first time I see someone trying to use unary arithmetics operators (++ and --) in this manner.   Isn't

          i = ++i

          an error as ++i will automatically increments i

          What happens when you try

          i += 1

          or

          ++i

          instead?  does that work?

          Bassam Khouri added a comment - I'm just commenting for the sake of commenting.  I'm not an expert in groovy but it's the first time I see someone trying to use unary arithmetics operators ( ++  and -- ) in this manner.   Isn't i = ++i an error as ++i will automatically increments i What happens when you try i += 1 or ++i instead?  does that work?

          Oleg Nenashev added a comment -

          jglick probably you have fixed it in the recent version, no?

          Oleg Nenashev added a comment - jglick probably you have fixed it in the recent version, no?

          Yuriy Burtsev added a comment -

          ++i does not work in any conditions.

          Yuriy Burtsev added a comment - ++i does not work in any conditions.

          Yuriy Burtsev added a comment -

          but in groovyConsole it work perfectly.

          Yuriy Burtsev added a comment - but in groovyConsole it work perfectly.

          Jesse Glick added a comment -

          oleg_nenashev I am not aware of this having been fixed recently, though of course it would be worth retesting in workflow-cps 2.34 just to check.

          Jesse Glick added a comment - oleg_nenashev I am not aware of this having been fixed recently, though of course it would be worth retesting in workflow-cps 2.34 just to check.

          Yuriy Burtsev added a comment -

          Jesse Glick, with Pipeline Groovy 2.34 the same error.

          Yuriy Burtsev added a comment - Jesse Glick, with Pipeline Groovy 2.34 the same error.

          Andrew Bayer added a comment -

          I'm pretty sure this actually works now, at least with Pipeline: Groovy version 2.36.1 or later. I've got tests in a PR for Declarative (using that version of Pipeline: Groovy) that use ++ and they pass.

          Andrew Bayer added a comment - I'm pretty sure this actually works now, at least with Pipeline: Groovy version 2.36.1 or later. I've got tests in a PR for Declarative (using that version of Pipeline: Groovy) that use ++ and they pass.

          Frederik Schreiber added a comment - - edited

          If using example in description it works, but if using Integer Object Wrapper the error still occure.

           

          example

          def testIncrement() {
              def i = ++Integer.parseInt("1")
          } 

           

          error:

          groovy.lang.MissingMethodException: No signature of method: com.cloudbees.groovy.cps.Builder.prefixInc() is applicable for argument types: (java.lang.Integer, com.cloudbees.groovy.cps.impl.FunctionCallBlock) values: [2, com.cloudbees.groovy.cps.impl.FunctionCallBlock@2e98ac68]
          Possible solutions: prefixInc(int, com.cloudbees.groovy.cps.LValueBlock), prefixDec(int, com.cloudbees.groovy.cps.LValueBlock), postfixInc(int, com.cloudbees.groovy.cps.LValueBlock)
          	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
          	at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
          	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
          	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
          	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)

           

          should i re-open ticket or should i create a new one abayer?

           

          my Pipeline Groovy Version: 2.74

          Frederik Schreiber added a comment - - edited If using example in description it works, but if using Integer Object Wrapper the error still occure.   example def testIncrement() { def i = ++ Integer .parseInt( "1" ) }   error: groovy.lang.MissingMethodException: No signature of method: com.cloudbees.groovy.cps.Builder.prefixInc() is applicable for argument types: (java.lang. Integer , com.cloudbees.groovy.cps.impl.FunctionCallBlock) values: [2, com.cloudbees.groovy.cps.impl.FunctionCallBlock@2e98ac68] Possible solutions: prefixInc( int , com.cloudbees.groovy.cps.LValueBlock), prefixDec( int , com.cloudbees.groovy.cps.LValueBlock), postfixInc( int , com.cloudbees.groovy.cps.LValueBlock) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)   should i re-open ticket or should i create a new one abayer ?   my Pipeline Groovy Version: 2.74

          Yuriy Burtsev added a comment -

          dealer The same error.

          Yuriy Burtsev added a comment - dealer  The same error.

          Nishith added a comment - - edited

          Something very similar I am facing. The following code works on groovy editor, but gives error when run from Jenkins pipeline>stage>script

          a = "2.15.0-abcde"
          b = a.split("
          .")[1] as Integer
          if ( b < 18)

          { ansible_ver = "2.7.10" }

          else

          { ansible_ver = "2.9.10" }

          print ansible_ver

           

          In Pipeline:

          roovy.lang.MissingMethodException: No signature of method: com.cloudbees.groovy.cps.Builder.prefixDec() is applicable for argument types: (java.lang.Integer, com.cloudbees.groovy.cps.impl.FunctionCallBlock) values: [2, com.cloudbees.groovy.cps.impl.FunctionCallBlock@5c0ef916]roovy.lang.MissingMethodException: No signature of method: com.cloudbees.groovy.cps.Builder.prefixDec() is applicable for argument types: (java.lang.Integer, com.cloudbees.groovy.cps.impl.FunctionCallBlock) values: [2, com.cloudbees.groovy.cps.impl.FunctionCallBlock@5c0ef916]Possible solutions: prefixDec(int, com.cloudbees.groovy.cps.LValueBlock), prefixInc(int, com.cloudbees.groovy.cps.LValueBlock), postfixDec(int, com.cloudbees.groovy.cps.LValueBlock) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) at WorkflowScript.__cps__60311(WorkflowScript) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:198) at WorkflowScript.<clinit>(WorkflowScript)Caused: java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.Class.newInstance(Class.java:442) at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:434) at groovy.lang.GroovyShell.parse(GroovyShell.java:700) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:571) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:523) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429)

           

          I have been struggling to make it work in Jenkins, but to no avail.

          Nishith added a comment - - edited Something very similar I am facing. The following code works on groovy editor, but gives error when run from Jenkins pipeline>stage>script a = "2.15.0-abcde" b = a.split(" .") [1] as Integer if ( b < 18) { ansible_ver = "2.7.10" } else { ansible_ver = "2.9.10" } print ansible_ver   In Pipeline: roovy.lang.MissingMethodException: No signature of method: com.cloudbees.groovy.cps.Builder.prefixDec() is applicable for argument types: (java.lang.Integer, com.cloudbees.groovy.cps.impl.FunctionCallBlock) values: [2, com.cloudbees.groovy.cps.impl.FunctionCallBlock@5c0ef916] roovy.lang.MissingMethodException: No signature of method: com.cloudbees.groovy.cps.Builder.prefixDec() is applicable for argument types: (java.lang.Integer, com.cloudbees.groovy.cps.impl.FunctionCallBlock) values: [2, com.cloudbees.groovy.cps.impl.FunctionCallBlock@5c0ef916] Possible solutions: prefixDec(int, com.cloudbees.groovy.cps.LValueBlock), prefixInc(int, com.cloudbees.groovy.cps.LValueBlock), postfixDec(int, com.cloudbees.groovy.cps.LValueBlock) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) at WorkflowScript.__ cps __60311(WorkflowScript) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:198) at WorkflowScript.<clinit>(WorkflowScript)Caused: java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.Class.newInstance(Class.java:442) at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:434) at groovy.lang.GroovyShell.parse(GroovyShell.java:700) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:571) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:523) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429)   I have been struggling to make it work in Jenkins, but to no avail.

            Unassigned Unassigned
            burtsevyg Yuriy Burtsev
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: