mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
fix(cpe) readToDisk failes with content from writeToDisk (#2629)
* branch for debugging * Add json fix for booleans * remove debug output * handle boolean in cpe * handle various types in json * fix variable Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
This commit is contained in:
parent
3df4542271
commit
2d93e5d4df
@ -228,7 +228,7 @@ class commonPipelineEnvironment implements Serializable {
|
||||
def param = fileName.split('/')[fileName.split('\\/').size()-1]
|
||||
if (param.endsWith(".json")){
|
||||
param = param.replace(".json","")
|
||||
valueMap[param] = script.readJSON(text: fileContent)
|
||||
valueMap[param] = getJSONValue(script, fileContent)
|
||||
}else{
|
||||
valueMap[param] = fileContent
|
||||
}
|
||||
@ -241,7 +241,7 @@ class commonPipelineEnvironment implements Serializable {
|
||||
def param = fileName.split('/')[fileName.split('\\/').size()-1]
|
||||
if (param.endsWith(".json")){
|
||||
param = param.replace(".json","")
|
||||
containerProperties[param] = script.readJSON(text: fileContent)
|
||||
containerProperties[param] = getJSONValue(script, fileContent)
|
||||
}else{
|
||||
containerProperties[param] = fileContent
|
||||
}
|
||||
@ -251,4 +251,26 @@ class commonPipelineEnvironment implements Serializable {
|
||||
List getCustomDefaults() {
|
||||
DefaultValueCache.getInstance().getCustomDefaults()
|
||||
}
|
||||
|
||||
def getJSONValue(Script script, String text) {
|
||||
try {
|
||||
return script.readJSON(text: text)
|
||||
} catch (net.sf.json.JSONException ex) {
|
||||
// JSON reader cannot handle simple objects like bool, numbers, ...
|
||||
// as such readJSON cannot read what writeJSON created in such cases
|
||||
if (text in ['true', 'false']) {
|
||||
return text.toBoolean()
|
||||
}
|
||||
if (text ==~ /[\d]+/) {
|
||||
return text.toInteger()
|
||||
}
|
||||
if (text.contains('.')) {
|
||||
return text.toFloat()
|
||||
}
|
||||
// no handling of strings since we expect strings in a non-json file
|
||||
// see handling of *.json above
|
||||
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user