fixed parse csv function

This commit is contained in:
Roberto Cirillo 2022-04-27 15:02:42 +02:00
parent 49b7269935
commit 9d5198c153
1 changed files with 11 additions and 25 deletions

36
Jenkinsfile vendored
View File

@ -92,7 +92,7 @@ pipeline {
steps {
sh '''
echo "Cron build enabled. New deploy of ${TRIGGER_JOB} - ${TRIGGER_VERSION} appended to the deploy file"
echo "${TRIGGER_JOB} , ${TRIGGER_VERSION}" >> ${DEPLOY_FILE}
echo "${TRIGGER_JOB},${TRIGGER_VERSION}" >> ${DEPLOY_FILE}
'''
}
}
@ -137,25 +137,8 @@ pipeline {
}
}
//a non CPS method is necessary for the usage of splitEachLine()
@NonCPS
def parseDeployComponent(def deployList) {
println "Going to parsing file ${deployList}"
def content = readCSV file : "${deployList}"
println "JOB REPORT CONTENT: ${content}"
def components = []
content.splitEachLine(/,/) { columns ->
if (columns[0].startsWith('#') || columns[0].startsWith('Component'))
return
components.add([
name : columns[0],
version : columns[1]
]
)
}
return components
}
//parse a csv file formatted in this way: ComponentName,ComponentVersion
def parseCSVList(def deployList) {
def components = []
if (fileExists("${deployList}")) {
@ -167,16 +150,19 @@ def parseCSVList(def deployList) {
version : fields[1]
]
)
// for(String item: fields) {
// println item
// println ' you are parsing line : ' + count
// }
}
}
} else {
echo ' File Not found. Failing.'
}
return components
}
//Alternative way to append a text in a small file (not used)
def appendToFile(String fileName, String line) {
def current = ""
if (fileExists(fileName)) {
current = readFile fileName
}
writeFile file: fileName, text: current + "\n" + line
}