5

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

4

1 回答 1

12

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

于 2016-03-17T21:01:53.047 回答