按行读文件
pipeline {
agent {label 'test'}
stages {
stage ("read file line"){
steps{
script {
def data = readFile(file: 'Jenkins/services.csv')
println(data)
//按行打印,打印一行之后暂停2秒
Thread.sleep(2000)
//按行读取
def lines = data.readLines()
//使用for循环遍历每行
for (line in lines) {
println(line)
//执行一些动作,如build另外一个job,以读取的行为参数
build job: 'LOCAL', parameters: [string(name: 'SERVICE', value: line)]
//假如是一个csv文件,每行都是以逗号分隔的参数,可以使用split取每一列,然后再做为参数传递给另外一个job
String[] str;
str = line.split(',');
println('projectkey:' + str[0])
println('reponame:' + str[1])
println('giturl:' + str[2])
build job: 'LOCAL', parameters: [string(name: 'username', value: str[0]),string(name: 'address', value: str[1]),string(name: 'phone', value: str[2])]
}
}
}
}
}
}
|