mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-05 13:25:19 +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:
parent
006aaab50d
commit
834dd1a1de
@ -192,36 +192,28 @@ class commonPipelineEnvironment implements Serializable {
|
|||||||
]
|
]
|
||||||
|
|
||||||
void writeToDisk(script) {
|
void writeToDisk(script) {
|
||||||
|
|
||||||
files.each({f ->
|
files.each({f ->
|
||||||
if (this[f.property] && !script.fileExists(f.filename)) {
|
writeValueToFile(script, f.filename, this[f.property])
|
||||||
script.writeFile file: f.filename, text: this[f.property]
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
containerProperties.each({key, value ->
|
containerProperties.each({key, value ->
|
||||||
def fileName = ".pipeline/commonPipelineEnvironment/container/${key}"
|
writeValueToFile(script, ".pipeline/commonPipelineEnvironment/container/${key}", value)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
valueMap.each({key, value ->
|
valueMap.each({key, value ->
|
||||||
def fileName = ".pipeline/commonPipelineEnvironment/custom/${key}"
|
writeValueToFile(script, ".pipeline/commonPipelineEnvironment/custom/${key}", value)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
void readFromDisk(script) {
|
||||||
files.each({f ->
|
files.each({f ->
|
||||||
if (script.fileExists(f.filename)) {
|
if (script.fileExists(f.filename)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user