Reputation: 115
I am facing
getThingsDone() is applicable for argument types: () values: []
error for code as below,
in shared library ....
vars/pipeline.groovy
def getThingsDone(m = null){
echo "done"
}
in some project that includes shared library
@Library(shared_pipeline@branch_name) _
pipeline.getThingsDone()
I tried with defining getThingsDone(...)
Nothing works. So I want to get a function that accepts no parameter(s) up and running. But it breaks up with the entire stack trace as below,
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.getThingsDone() is applicable for argument types: () values: []
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:64)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:155)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:133)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:120)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:153)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:157)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
at WorkflowScript.run(WorkflowScript:7)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:77)
at sun.reflect.GeneratedMethodAccessor208.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:83)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:35)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:331)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:243)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:231)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
Upvotes: 4
Views: 42520
Reputation: 1485
Don't name the groovy files inside the /vars
folder pipeline.groovy
because pipeline is also a jenkins function. doint so would call the jenkins function instead, which has a different signature.
Renaming my .groovy
file solved the problem for me.
Upvotes: 0
Reputation: 14527
The Problem: you configured an external Jenkins shared library that contains some functions you want to use in your jenkins pipeline. However, your Jenkins doesn't recognize the method signature and throws an exception.
issue:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException:
No signature of method: java.lang.Class.someMethodName()
Solution:
the relations between the to would be like:
<shared library> contains: <some function> -> jenkins imports this function and can use it.
validate the function name doesn't have Typo or Missing Characters, validate that the input arguments in the right order.
You need to verify that the library is imported correctly.
@Library('my-shared-library') _
/* Using a version specifier, such as branch, tag, etc */
@Library('[email protected]') _
/*Accessing multiple libraries with one statement */
@Library(['my-shared-library', 'otherlib@abc1234']) _
The global function should be wrapped in script directive, for example the file name: startServer.groovy
#!/usr/bin/env groovy
def call() {
script{
sh """#!/bin/bash -le
cd ${workspace}/app
npm start
"""
}
}
[on jenkins pipeline:]
//pipeline code...
startServer()
If you declare a static function inside a groovy class, make sure that the class is starting with lowercase letter. for example use: nodeUtils.groovy
and NOT Nodeutils.groovy
(it's for some reason unrecognized)
#!/usr/bin/env groovy
def startServer() {
script{
sh """#!/bin/bash -le
cd ${workspace}/app
npm start
"""
}
}
def installPackages() {
script{
sh """#!/bin/bash -le
cd ${workspace}/app
npm install --save-dev
"""
}
}
[on jenkins pipeline:]
//pipeline code...
nodeUtils.installPackages()
Upvotes: 3
Reputation: 115
global variables need to accessed from script directive
In above case, getThingsDone() is a global function. And according to https://issues.jenkins-ci.org/browse/JENKINS-42360, global variables/functions are not allowed to be used outside of script directive.
Upvotes: 5