Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-46167

Writing variables in JSON using writeJson of Pipeline Utility

      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.

          [JENKINS-46167] Writing variables in JSON using writeJson of Pipeline Utility

          Daniel Alejandro Hernández created issue -
          Daniel Alejandro Hernández made changes -
          Description Original: While trying to assign variables into some JSON file readed in a Pipeline Project.

           Using this JSON file file.json:


          {code: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"}]
          {code}


          You do:


          {code:groovy}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          buildNumberVar = "xx"
          jsonEnvDefinition['buildNumber'] = "${buildNumberVar}"
          echo "${jsonDictionary }"
          {code}


          I am getting in the output:

          {code:json}
          [[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]]
          {code}


          Which doesn't make sense. Instead if I hard coded the value


          {code:groovy}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          jsonEnvDefinition['buildNumber'] = "xx"
          echo "${jsonDictionary }"
          {code}


          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 makes 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.


          New: While trying to assign variables into some JSON file readed in a Pipeline Project.

           Using this JSON file file.json:


          {code: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"
             }
          ]
          {code}


          You do:


          {code:groovy}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          buildNumberVar = "xx"
          jsonEnvDefinition['buildNumber'] = "${buildNumberVar}"
          echo "${jsonDictionary }"
          {code}


          I am getting in the output:

          {code:json}
          [[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]]
          {code}


          Which doesn't make sense. Instead if I hard coded the value


          {code:groovy}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          jsonEnvDefinition['buildNumber'] = "xx"
          echo "${jsonDictionary }"
          {code}


          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 makes 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.


          Daniel Alejandro Hernández made changes -
          Description Original: While trying to assign variables into some JSON file readed in a Pipeline Project.

           Using this JSON file file.json:


          {code: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"
             }
          ]
          {code}


          You do:


          {code:groovy}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          buildNumberVar = "xx"
          jsonEnvDefinition['buildNumber'] = "${buildNumberVar}"
          echo "${jsonDictionary }"
          {code}


          I am getting in the output:

          {code:json}
          [[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]]
          {code}


          Which doesn't make sense. Instead if I hard coded the value


          {code:groovy}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          jsonEnvDefinition['buildNumber'] = "xx"
          echo "${jsonDictionary }"
          {code}


          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 makes 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.


          New: While trying to assign variables into some JSON file readed in a Pipeline Project.

           Using this JSON file file.json:


          {code:none}
          [
             {
                "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"
             }
          ]
          {code}


          You do:


          {code:none}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          buildNumberVar = "xx"
          jsonEnvDefinition['buildNumber'] = "${buildNumberVar}"
          echo "${jsonDictionary }"
          {code}


          I am getting in the output:

          {code:none}
          [[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]]
          {code}


          Which doesn't make sense. Instead if I hard coded the value


          {code:none}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          jsonEnvDefinition['buildNumber'] = "xx"
          echo "${jsonDictionary }"
          {code}


          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 makes 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.


          Daniel Alejandro Hernández made changes -
          Description Original: While trying to assign variables into some JSON file readed in a Pipeline Project.

           Using this JSON file file.json:


          {code:none}
          [
             {
                "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"
             }
          ]
          {code}


          You do:


          {code:none}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          buildNumberVar = "xx"
          jsonEnvDefinition['buildNumber'] = "${buildNumberVar}"
          echo "${jsonDictionary }"
          {code}


          I am getting in the output:

          {code:none}
          [[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]]
          {code}


          Which doesn't make sense. Instead if I hard coded the value


          {code:none}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          jsonEnvDefinition['buildNumber'] = "xx"
          echo "${jsonDictionary }"
          {code}


          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 makes 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.


          New: While trying to assign variables into some JSON file readed in a Pipeline Project.

           Using this JSON file file.json:


          {code:none}
          [
             {
                "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"
             }
          ]
          {code}


          You do:


          {code:none}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          buildNumberVar = "xx"
          jsonEnvDefinition['buildNumber'] = "${buildNumberVar}"
          echo "${jsonDictionary }"
          {code}


          I am getting in the output:

          {code:none}
          [[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]]
          {code}


          Which doesn't make sense. Instead if I hard coded the value


          {code:none}
          jsonDictionary = readJSON file: "file.json"
          jsonEnvDefinition = jsonDictionary.get(0);
          jsonEnvDefinition['buildNumber'] = "xx"
          echo "${jsonDictionary }"
          {code}


          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.


            rsandell rsandell
            danielahcardona Daniel Alejandro Hernández
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: