我在Jenkins groovy脚本中有一个小的测试阶段,可以通过循环到一个csv文件中来获取分支值,当我不在循环中不包含HELM_REPO_BRANCH时出现了问题,但是java.io.NotSerializableException:com失败了。如果我尝试从另一个函数中获取值,则xlson.groovycsv.CsvIterator错误。知道如何解决吗?。
stage("Deploy missing Services to ${DEST_ENV}"){
sh 'echo NAME,VERSION >test.csv'
sh 'echo account,1.17.1 >>test.csv'
sh 'echo payment,1.6.9 >>test.csv'
def csv = readFile 'test.csv'
def data = new CsvParser().parse(csv)
for( line in data ) {
def SERVICE_NAME = "$line.NAME"
def SRC_VERSION = "$line.VERSION"
def HELM_REPO_BRANCH = get_job_parameters()
echo "$SERVICE_NAME"
echo "$SRC_VERSION"
echo "$HELM_REPO_BRANCH"
}
}
def get_job_parameters() {
BRANCH= readFile 'deployment_branch.txt'
return BRANCH
}
答案 0 :(得分:0)
您可以使用readCSV(假设该阶段已经在node
块的上下文中运行):
stage("Deploy missing Services to ${DEST_ENV}") {
writeFile file: 'test.csv', text: '''NAME,VERSION
account,1.17.1
payment,1.6.9'''
def csv = readCSV(file: 'test.csv', format: CSVFormat.DEFAULT.withHeader())
csv.each { record ->
def SERVICE_NAME = record.get('NAME')
def SERVICE_VERSION = record.get('VERSION')
...
}
}