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

writeJson step to serialize to string variable

XMLWordPrintable

      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.

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

              Created:
              Updated: