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.
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
an error as ++i will automatically increments i
What happens when you try
or
instead? does that work?