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

readProperties read file does not support UTF-8 encoding

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • jenkins 2.249.3
      jdk8
      ubuntu
      pipeline-utility-steps 2.6.2

      I readProperties from file, but some value is garbled, seem not encoding. Looks like this “邱乐平”

      I try readFile it can work well.Especially the properties file contains Chinese characters 。

      so i workaround like this

      def gerritcfg = readFile file:filename
      def props =   readProperties text:gerritcfg
      println props
      

      here another test pipeline code:

      node {
          filename= "pipeline-utility-steps-plugin/work/test.properties"
          def properties = readFile file:filename
          def props1 =   readProperties text:properties 
          def props2 =   readProperties file:filename 
          println props1
          println props2
      }
      
      $ file test.properties                                                                                                                                                                                                                                            
      test.properties: UTF-8 Unicode text
      
      the properties file looks like below:
      $ cat test.properties                                                                                                                                                                                                                                             
      prop1=abcabc123
      prop2=中国中国
      

      the pipeline console output.

      Started by user unknown or anonymous
      Replayed #8
      Running in Durability level: MAX_SURVIVABILITY
      [Pipeline] node
      Running on Jenkins in /work/brightma/github/pipeline-utility-steps-plugin/work/workspace/test_pipe
      [Pipeline] {
      [Pipeline] readFile
      [Pipeline] readProperties
      [Pipeline] readProperties
      [Pipeline] echo
      {prop2=中国中国, prop1=abcabc123}
      [Pipeline] echo
      {prop2=中国中国, prop1=abcabc123}
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

            rsandell rsandell
            mmh19891113 bright.ma
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: