I've defined a class SomeClass
with a method
class SomeClass implements Serializable {
void someMethod(String var1, String var2, String... vars) {
...
}
}
which I'm using in a declarative pipeline as follows:
SomeClass instance = new SomeClass(this)
pipeline {
environment {
VAR1 = "var1"
VAR2 = sh(returnStdout: true, script: "echo var2").trim()
VAR3 = "var3"
}
stages {
stage("Stage X") {
steps {
script {
instance.someMethod("${VAR1}", "${VAR2}", "${VAR3}")
}
}
}
}
}
which fails due to
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.docker.workflow.SomeClass.someMethod() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, org.codehaus.groovy.runtime.GStringImpl, org.codehaus.groovy.runtime.GStringImpl) values: [var1, var2, var3]
If I change the invocation to instance.someMethod(VAR1.toString(), VAR2.toString(), VAR3.toString())
it fails due to
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.docker.workflow.SomeClass.someMethod() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [var1, var2, var3]
Afaik at least one of them should work. I think Groovy should be capable of making both work, but that's a second step. How can I invoke the method with the given arguments?