I'm trying to define a variable into a jenkins pipeline dsl script by reading 3 files and concatenating the output. The 3 files content is:
file1 content is: 127
file2 content is: 0
file3 content is: 1
def var1 = readfile('file1')
def var2 = readfile('file2')
def var3 = readfile('file3')
def concatVar = "${var1} + '_' + ${var2} + '_' + ${var3}"
printin ${concatVar}
The output I expect would be
printIn${concatVar}
127_0_1
instead my output is:
printIn ${concatVar}
127
_0
_1
I know that I am wrong somewhere, but I don't know how to do it. Is there any of you familiar with the Jenkins pipepile dsl/groovy syntax?
Thanks guys
Try this..
def var1 = readfile('file1').trim()
def var2 = readfile('file2').trim()
def var3 = readfile('file3').trim()
def concatVar = "${var1} + '_' + ${var2} + '_' + ${var3}"
println ${concatVar}
I found that readFile does not clip off the end of line character
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With