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

writeJson step to serialize to string variable

      the writeJSON step currently only allows for serialization of a variable object (map, list etc) to file, but for certain operations (such as executing an adhoc curl), it would be nice if you could serialize to a string and then use that as part of the call.

      For example:

      sh (script: "curl -s http://localhost/rpc -d '{ \"field1\": 123 }' -H 'Content-Type: application/json'")

      Could be re-written as:

      def bodyMap = readJSON text: '{}'
      bodyMap.field1 = 123 
      def jsonStr = writeJSON json: bodyMap
      sh (script: "curl -s http://localhost/rpc -d '${jsonStr}' -H 'Content-Type: application/json'")

      Granted you could just serialize to file and then pass that file to the curl command.

          [JENKINS-48148] writeJson step to serialize to string variable

          Chris White created issue -
          Chris White made changes -
          Description Original: the writeJSON step currently only allows for serialization of a variable object (map, list etc) to file, but for certain operations (such as executing an adhoc curl), it would be nice if you could serialize to a string and then use that as part of the call.

          For example:
          {code:java}
          sh (script: "curl -s http://localhost/rpc -d '{ \"field1\": 123 }' -H 'Content-Type: application/json'"){code}
          Could be re-written as:
          {code:java}
          def bodyMap = readJSON text: '{}'
          bodyMap.field1 = 123
          def jsonStr = writeJSON json: bodyMap
          sh (script: "curl -s http://localhost/rpc -d '${jsonStr}' -H 'Content-Type: application/json'){code}
          Granted you could just serialize to file and then pass that file to the curl command.
          New: the writeJSON step currently only allows for serialization of a variable object (map, list etc) to file, but for certain operations (such as executing an adhoc curl), it would be nice if you could serialize to a string and then use that as part of the call.

          For example:
          {code:java}
          sh (script: "curl -s http://localhost/rpc -d '{ \"field1\": 123 }' -H 'Content-Type: application/json'"){code}
          Could be re-written as:
          {code:java}
          def bodyMap = readJSON text: '{}'
          bodyMap.field1 = 123
          def jsonStr = writeJSON json: bodyMap
          sh (script: "curl -s http://localhost/rpc -d '${jsonStr}' -H 'Content-Type: application/json'"){code}
          Granted you could just serialize to file and then pass that file to the curl command.
          Basil Peace made changes -
          Link New: This issue is duplicated by JENKINS-63720 [ JENKINS-63720 ]

            rsandell rsandell
            chriswhite199 Chris White
            Votes:
            6 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: