1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-30 05:59:39 +02:00

fix(CPE): correct handling of complex (json) data in writeToDisk (#2500)

* correct handling of JSON data

* fix typo

* Update commonPipelineEnvironment.groovy
This commit is contained in:
Christopher Fenner 2021-01-11 12:58:12 +01:00 committed by GitHub
parent 006aaab50d
commit 834dd1a1de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -192,36 +192,28 @@ class commonPipelineEnvironment implements Serializable {
]
void writeToDisk(script) {
files.each({f ->
if (this[f.property] && !script.fileExists(f.filename)) {
script.writeFile file: f.filename, text: this[f.property]
}
writeValueToFile(script, f.filename, this[f.property])
})
containerProperties.each({key, value ->
def fileName = ".pipeline/commonPipelineEnvironment/container/${key}"
if (value && !script.fileExists(fileName)) {
if(value in CharSequence) {
script.writeFile file: fileName, text: value
} else {
script.writeFile file: fileName, text: groovy.json.JsonOutput.toJson(value)
}
}
writeValueToFile(script, ".pipeline/commonPipelineEnvironment/container/${key}", value)
})
valueMap.each({key, value ->
def fileName = ".pipeline/commonPipelineEnvironment/custom/${key}"
if (value && !script.fileExists(fileName)) {
if(value in CharSequence) {
script.writeFile file: fileName, text: value
} else {
script.writeFile file: fileName, text: groovy.json.JsonOutput.toJson(value)
}
}
writeValueToFile(script, ".pipeline/commonPipelineEnvironment/custom/${key}", value)
})
}
void writeValueToFile(script, String filename, value){
if (value){
if (!value in CharSequence) filename += '.json'
if (script.fileExists(filename)) return
if (!value in CharSequence) value = groovy.json.JsonOutput.toJson(value)
script.writeFile file: filename, text: value
}
}
void readFromDisk(script) {
files.each({f ->
if (script.fileExists(f.filename)) {