Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins dsl pipeline def variable

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

like image 491
Asgard Avatar asked Mar 08 '16 23:03

Asgard


1 Answers

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

like image 89
jvanryn Avatar answered Nov 02 '22 03:11

jvanryn