0
votes

Edit: Full script is just two lines now. This used to work and stopped working after I once changed jdk.

+ not working to concatenate strings (full script)

output = "hello" + "," + "world"
println output

Output

groovy.lang.MissingMethodException: No signature of method:

Script1.hello() is applicable for argument types: (java.lang.String)

values: [,] Possible solutions: getAt(java.lang.String), sleep(long),

each(groovy.lang.Closure), split(groovy.lang.Closure) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:81)

Although the concat function works fine

output = ("hello".concat(",")).concat("world")
println output
2
How is output declared? What type is u? What type does u.getId() return? How is email declared, and what does it contain? - Chris Long
Just to have it mentioned: the idiomatic way to write that in groovy would be "${u.id},${email}" - cfrick
@ChrisLong, it doesn't matter as they are strings. I tried with "hello" +"," +"world" still same - HumayunM
The error happens `at Script1.groovy line 11). I believe that problem not in concatenation. Show what do you have at line 11, and better whole script. - daggett
This looks fishy: No signature of method: java.lang.String.,() The dot comma parens. Show your code, especially line 11 - ou_ryperd

2 Answers

0
votes

this question about shell and jenkins api. and not about groovy...

after injecting of script body in shell instead of $(cat ...) you get the following command line

-d "script=output = "hello" + "," + "world""

that is wrong url-encoded parameter

try --data-urlencode instead of -d

curl --data-urlencode "script=$(cat Script.groovy)" ...

probably you have to play with doublequotes after that...

0
votes

DISCLAIMER: I don't know Jenkin-Groovy much.

Script1.hello() is applicable for argument types: (java.lang.String)

The above line, in your error trace, implies that it's taking your string "hello", as a method, in Script1. Precisely, it's trying to execute, sort of, Script1.hello(String s), by passing "," as an argument. Since, there is none, it throws an error.

I'm not sure but how about trying this, instead

output = 'hello' + ',' + 'world'
println output

NB: There is a difference in single-quoted (String) and double-quoted (GString) in Groovy

Or, this

hello = 'hello'
world = 'world'
output = "$hello, $world"
println output