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

file list values are returned as a single string

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • active-choices-plugin
    • OS: Redhat 64bit 5.x
      Jenkins 1.610
      uno choice plugin 0.22
      Firefox
      java 1.7

      Requirement:

      • place the choice contents(a1,a2,a3,a4) in a file at unix, with help of Groovy script get the contents and return the list

      What works:
      ------------
      def list1 = ["a1", "a2", "a3" ]
      return list1
      -----------------

      What doesn't work:
      — keeping the choice contents in a unix file and pulling the list using groovy script and return the values.
      vi groovey1
      "t1",
      "t2",
      "t3",
      ---------
      Groovy script:
      ----------------
      def File file = new File("/infapoc2/jenkins/Scripts/reports/script_report/groovey1")
      def fileContent = file.getText()
      return [fileContent]
      ------------
      Output: o "t1", "t2", "t3"

      but expected "
      o t1
      o t2
      o t3

          [JENKINS-29431] file list values are returned as a single string

          remember that you must return a list or a map for having multiple options (one per list or map element)

          The file.getText() method returns a String and this is what you get.
          To get the expected output you should try something like

          options=[]
          fileContent.split(',').each{
          options.add(it)
          }
          return options
          

          Please, let us know how this works for you.

          Ioannis Moutsatsos added a comment - remember that you must return a list or a map for having multiple options (one per list or map element) The file.getText() method returns a String and this is what you get. To get the expected output you should try something like options=[] fileContent.split( ',' ).each{ options.add(it) } return options Please, let us know how this works for you.

          Ping nikhilpotti

          Did you take a look at ioannis's comment?

          Bruno P. Kinoshita added a comment - Ping nikhilpotti Did you take a look at ioannis 's comment?

          nikhil potti added a comment -

          Yes, it worked thank you Ioannis Moutsatsos and Bruno P. Kinoshita

          nikhil potti added a comment - Yes, it worked thank you Ioannis Moutsatsos and Bruno P. Kinoshita

          nikhil potti added a comment -

          it is working fine with below option:

          options=[]
          fileContent.split(',').each{
          options.add(it)
          }
          return options

          nikhil potti added a comment - it is working fine with below option: options=[] fileContent.split(',').each{ options.add(it) } return options

          Thank you for your feedback nikhilpotti!!

          Bruno P. Kinoshita added a comment - Thank you for your feedback nikhilpotti !!

            kinow Bruno P. Kinoshita
            nikhilp2111 nikhil potti
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: