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

JSON-editor File upload is not working and is blocking the whole display

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Critical Critical
    • None
    • Ubuntu 14.04 x64
      Oracle JDK 1.7.0_80
      Extended Choice Parameter Plug-In 0.64

      JSON-Editor itself supports File upload feature.
      I have tested my JSON code at http://jeremydorn.com/json-editor/.

      When I added the code (the File upload block) to the existing " JSON Parameter Config Groovy Script",
      the JSON-Editor UI doesn't show up anymore.
      I have approved groovy script in "In-process script approval" before tryout to trigger the job.

      Attach screen shot files:
      Selection_010.png (expected UI output displayed at http://jeremydorn.com/json-editor/)
      Selection_011.png (tested JSON Schema at http://jeremydorn.com/json-editor/)
      Selection_012.png (Jenkins display output with File upload code)
      Selection_012.png (Jenkins display output without File upload code)
      JSON Parameter Config Groovy Script.txt (groovy source code in Jenkins Job config)

        1. JSON Parameter Config Groovy Script.txt
          1 kB
        2. Selection_010.png
          Selection_010.png
          89 kB
        3. Selection_011.png
          Selection_011.png
          67 kB
        4. Selection_012.png
          Selection_012.png
          68 kB
        5. Selection_013.png
          Selection_013.png
          129 kB

          [JENKINS-34440] JSON-editor File upload is not working and is blocking the whole display

          vimil added a comment - - edited

          Since you are using a slashy string, you will have to escape the slash. Try the below script to fix the issue.

          import org.boon.Boon;
          
          def jsonEditorOptions = Boon.fromJson(/{
          disable_edit_json: false,
          disable_properties: false,
          no_additional_properties: false,
          disable_collapse: true,
          disable_array_add: false,
          disable_array_delete: false,
          disable_array_reorder: true,
          theme: "bootstrap3",
          iconlib:"bootstrap3",
          
          schema: {
          "title": "SVN Permission for Branch: xxxxx",
          "type": "array",
          "format": "table",
          "uniqueItems": true,
                  "items": {
                          "type": "object",
                          "title": "User",
                          "properties": {
                                  "Username": {
                                          "type": "string",
                                          "propertyOrder": 1
                                  },
                                  "Permission": {
                                          "type": "string",
                                          "propertyOrder": 2,
                                          "enum": [
                                                  "RO",
                                                  "RW",
                                                  "NO",
                                                  ""
                                          ],
                                          "default": ""
                                  },
          						"File": {
          							"type": "string",
          							"propertyOrder": 3,
          							"media": {
          								"binaryEncoding": "base64",
          								"type": "image\/png"
          							},
          							"options": {
          								"include_filename": true
          							}
          						}
                          }
                  }
          }
          startval: [
                  {"Username": "user2", "Permission":"RW" },
                  {"Username": "user3", "Permission":"RW" },
                  {"Username": "user4", "Permission":"RW" },
          ]
          }/);
          
          return jsonEditorOptions;
          

          vimil added a comment - - edited Since you are using a slashy string, you will have to escape the slash. Try the below script to fix the issue. import org.boon.Boon; def jsonEditorOptions = Boon.fromJson(/{ disable_edit_json: false , disable_properties: false , no_additional_properties: false , disable_collapse: true , disable_array_add: false , disable_array_delete: false , disable_array_reorder: true , theme: "bootstrap3" , iconlib: "bootstrap3" , schema: { "title" : "SVN Permission for Branch: xxxxx" , "type" : "array" , "format" : "table" , "uniqueItems" : true , "items" : { "type" : "object" , "title" : "User" , "properties" : { "Username" : { "type" : "string" , "propertyOrder" : 1 }, "Permission" : { "type" : "string" , "propertyOrder" : 2, " enum " : [ "RO" , "RW" , "NO" , "" ], " default " : "" }, "File" : { "type" : "string" , "propertyOrder" : 3, "media" : { "binaryEncoding" : "base64" , "type" : "image\/png" }, "options" : { "include_filename" : true } } } } } startval: [ { "Username" : "user2" , "Permission" : "RW" }, { "Username" : "user3" , "Permission" : "RW" }, { "Username" : "user4" , "Permission" : "RW" }, ] }/); return jsonEditorOptions;

          vimil added a comment -

          there is a syntax error in the groovy script, correcting that fixes the issue

          vimil added a comment - there is a syntax error in the groovy script, correcting that fixes the issue

          Rick Liu added a comment -

          Thank you vimil~
          after escape the slash,
          now the file upload shows up correctly.

          But I got 2 other problems:
          1. There's no corresponding file created in WORKSPACE.
          I guess for this one, I need to manually decode BASE64 data to restore the file.

          2.
          It seems easily overflow the Jenkins argument list with a small 2MB text file.
          FATAL: command execution failed
          java.io.IOException: Cannot run program "/bin/bash" (in directory "/home/devops/jenkins_slave/workspace/Test/test-JSON_UI"): error=7, Argument list too long
          I'll create another ticket for this one.

          Rick Liu added a comment - Thank you vimil~ after escape the slash, now the file upload shows up correctly. But I got 2 other problems: 1. There's no corresponding file created in WORKSPACE. I guess for this one, I need to manually decode BASE64 data to restore the file. 2. It seems easily overflow the Jenkins argument list with a small 2MB text file. FATAL: command execution failed java.io.IOException: Cannot run program "/bin/bash" (in directory "/home/devops/jenkins_slave/workspace/Test/test-JSON_UI"): error=7, Argument list too long I'll create another ticket for this one.

          Rick Liu added a comment -

          Thank You vimil~
          I created JENKINS-34478 for question #2 above.

          I have another question regarding to JSON's File option:
          "File": {
          "type": "string",
          "propertyOrder": 3,
          "media":

          { "binaryEncoding": "base64", "type": "image\/png" }

          ,
          "options":

          { "include_filename": true }

          }

          Do I have to predefine "binaryEncoding" and "type"?
          If I want to allow user to upload either text files, or tarball files, or image files,
          then what should I put?

          Rick Liu added a comment - Thank You vimil~ I created JENKINS-34478 for question #2 above. I have another question regarding to JSON's File option: "File": { "type": "string", "propertyOrder": 3, "media": { "binaryEncoding": "base64", "type": "image\/png" } , "options": { "include_filename": true } } Do I have to predefine "binaryEncoding" and "type"? If I want to allow user to upload either text files, or tarball files, or image files, then what should I put?

            vimil vimil
            totoroliu Rick Liu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: