将file用作数组,并将对象作为变量存储在Jenkinsfile中



pseudo code中,我希望在groovy中实现这一点。

file 
a a1 a2 a3
b b1 b2 b3
c c1 c2 c3
file = /path/to/file
for (line in file) {
var_1=line1.a
var_2=line.a2
var_3=line.a3
}
echo $var_1
echo $var_2
echo $var_3
new File('/path/to/file').withReader("UTF-8"){r->
def headers=null
r.eachLine{line, index->
line = line.split(' ') //one space is a column delimiter
if(index==1){
//convert first line to a map - [ column-index : column-name ]
headers=line.toList().indexed()
}else{
//convert line to headers-to-values map to be able to access value by column name
line = headers.collectEntries{k,v-> [v, line[k]] }
println line.a
println line.b
println line.c
}
}
}

最新更新