Shared library: custom step help

Following this section of jenkins documentation, I’ve defined a global var in:

my-shared-library/vars/unLabel.groovy

The library is loaded implicitly and the code is:

def call(String labelName, String tfsPath) {
    echo "Hello, ${labelName} ${tfsPath}"             
}

Next I created a simple pipeline with two parameter FOO and BAR and the script is:

label 'my-agent'
unLabel ${params.FOO}, ${params.BAR}

I got this exception:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.workflow.cps.UninstantiatedDescribableWithInterpolation.unLabel() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, org.codehaus.groovy.runtime.GStringImpl) values: [test1, test2]

Even if I call:

 unLabel "test1", "test2" 

or

 unLabel("test1","test2")

it doesn’t work.

I’ve made a syntax error and I got an exception that shows that the variable is defined:

java.lang.NoSuchMethodError: No such DSL method '$' found among steps [....] or globals [..., env, params, pipeline, scm, unLabel]

So what is wrong here, can someone help me, please?

Double quotes strings are not strings but gstrings. I’ve been bit by that. You can convert a gstring to a string, but its easier to just not type your arguments in your function.

Thanks for reply.

Changing definition:

def call(labelName, tfsPath) {
    echo "Hello, ${labelName} ${tfsPath}"             
}

And changing invocation:

 unLabel params.FOO, params.BAR

Now the error is:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.workflow.cps.UninstantiatedDescribableWithInterpolation.unLabel() is applicable for argument types: (java.lang.String, java.lang.String) values: [test1, test2]

Finally I found that the problem here was label 'my-agent' that is not valid in a scripted pipeline. I changed my script with:

node('my-agent') {
  unLabel params.FOO, params.BAR
}

And it works.