-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
Jenkins 2.60.2
While trying to assign variables into some JSON file readed in a Pipeline Project.
Using this JSON file file.json:
[ { "id":"1", "buildNumber":"", "lock":"false", "tag":"dbaix", "configurationFile":"path/someFile.properties" }, { "id":"2", "buildNumber":"", "lock":"true", "tag":"dbaix", "configurationFile":"path/someFile.properties" }, { "id":"3", "buildNumber":"2222222", "lock":"true", "tag":"dbaix", "configurationFile":"path/someFile.properties" } ]
You do:
jsonDictionary = readJSON file: "file.json" jsonEnvDefinition = jsonDictionary.get(0); buildNumberVar = "xx" jsonEnvDefinition['buildNumber'] = "${buildNumberVar}" echo "${jsonDictionary }"
I am getting in the output:
[[id:1, buildNumber:[bytes:[120, 120], strings:[, ], valueCount:1, values:[xx]], lock:true, tag:dbaix, configurationFile:path/someFile.properties], [id:2, buildNumber:, lock:true, tag:dbaix, configurationFile:path/someFile.properties], [id:3, buildNumber:2222222, lock:true, tag:dbaix, configurationFile:path/someFile.properties]]
Which doesn't make sense. Instead if I hard coded the value
jsonDictionary = readJSON file: "file.json" jsonEnvDefinition = jsonDictionary.get(0); jsonEnvDefinition['buildNumber'] = "xx" echo "${jsonDictionary }"
I will get in the output:
[[id:1, buildNumber:xx, lock:true, tag:dbaix, configurationFile:path/someFile.properties], [id:2, buildNumber:, lock:true, tag:dbaix, configurationFile:path/someFile.properties], [id:3, buildNumber:2222222, lock:true, tag:dbaix, configurationFile:path/someFile.properties]]
Which make sense. I am expecting "xx" in buildNumber, but when using variables it is getting written some more complex string which I don't know how that value it is been created.
I discovered an awkward workaround, while doing this now it worked for me:
String buildNumberVar = "xx"
echo "buildNumberVar = ${buildNumberVar}"
jsonEnvDefinition['buildNumber'] = " " + buildNumberVar
Concatenating a empty String with t he buildNumberVar it worked.