Writing variables in JSON using writeJson of Pipeline Utility

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      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.

            Assignee:
            rsandell
            Reporter:
            Daniel Alejandro Hernández
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: