There is a job which will run daily to collect some info on Jenkins.
For debug, I will print one ArrayList to Jenkins console for possible further debug.
So I run inspect()
to print it, and find it's not working as expected.
If all the elements of an array and keys/values of a map are all quoted, I can directly copy paste the output to somewhere else for debug.
Short demo:
// Code
def hz = "3.90GHz"
def info = [["CPU": "CPU @ ${hz}"], ['HOST_OS':"Debian"]]
println(info.inspect())
// Output
[['CPU':CPU @ 3.90GHz], ['HOST_OS':'Debian']]
I find the value of "CPU" is not quoted.
My current fix(Add toString()
to the GString):
// Code
def hz = "3.90GHz"
def info = [["CPU": "CPU @ ${hz}".toString()], ['HOST_OS':"Debian"]]
println(info.inspect())
// Output
[['CPU':'CPU @ 3.90GHz'], ['HOST_OS':'Debian']]
I get two questions:
inspect()
seems not woking well with GString, is this expected, or a bug? Seems from theInvokerHelper
class, runinspect()
on "GString", it will runreturn arguments.toString();
, so no quotes.- Is there a better solution, other than adding
toString()
to GString?
Thanks in advance.