Jenkins does not recognize the cause of Chinese troubleshooting and solution

Jenkins does not recognize the cause of Chinese troubleshooting and solution

1. This article solves the problem

  1. When jenkins creates a task, there is no problem with naming letters in English, but once written in Chinese, an error will be reported. For example, an error occurred Malformed input or input contains unmappable chacrater.
  2. When the jenkins build log is printed, it becomes unrecognizable for Chinese ???.

2. Deployment

   Ours jenkinsis deployed in centosthe server and run directly with the image downloaded by docker. The version is Jenkins 2.303.1.

3. Troubleshooting

   If Chinese is not recognized, it must indicate that there is a problem with the character set encoding, so our idea must be to confirm jenkinswhether the character set encoding is correct utf-8.

3.1 View system information code

   For example, if your jenkinsaddress is http://localhost:8083, then visit http://localhost:8083//systemInfoto display the page of system information. (You can also click [System Management]-[Status Information]-[System Information] to view), as shown in the figure below:
insert image description here
   In addition to the frame selection in the above picture, there is a variable at the bottom of this page that sun.jnu.encodingis not correct utf-8, obviously jenkinsthe coding is wrong.

3.2 Check the system configuration code

   The location of the system configuration is in [System Management] - [System Configuration] - [System Configuration], check the variable value in it LANG. Pictured below:
insert image description here
   The picture above was originally not C.UTF-8, yes zh.CN.UTF-8. Why this is changed here will be explained below.

4. Problem solving steps

   Now that I knew it was an encoding problem, I started to modify the encoding. This is how I solved it.

4.1 docker startup script modification

   Because we are using dockerthe running, for 3.1the encoding problem shown above, I added the things selected in the lower border to the startup script:
insert image description here
   the first one is to make the font in the container consistent with the host machine (maybe it has nothing to do with this) .
   The second sentence is mainly to set LANGthe variable to C.UTF-8, which I set at first zh.CN.UTF-8, but it didn’t work, and then I found the following sentence, and suddenly realized.
insert image description here
   If it is not set when the container is created LANG=C.UTF-8, it will lead to entering the container, no matter how you pass exportor sourcecommand to modify the variable, it will be invalid when you exit the container.
   The third sentence is to ensure that 3.1 file.encodingbecomes utf-8.

4.2 Modify LANGparameters on the jenkins interface

  At first, I just changed the encoding of the docker startup script according to the 4.1 step, but I found that during jenkinsthe build, the log has always been ???this thing. I went to the position 3.2 above. Modified LANGvariables. As shown below:
insert image description here

5. Special instructions

  Many small partners may dockernot be very clear about how the container looks at the code. You can follow the steps below.
insert image description here
  If you don't modify it here, sometimes the default is enthe beginning, and sometimes it is POSIX.
   To set variables in the docker startup script, you need to -epass parameters, that is,
insert image description here
   some people think that localesetting variables under the previous command LC_ALLcan LC_*change all the variables, but I haven't tried it.
  The above are the problems I encountered and the solutions.

Guess you like

Origin blog.csdn.net/wohaqiyi/article/details/123851697