Jenkins does not recognize the cause of Chinese troubleshooting and solution
1. This article solves the problem
- 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
. - When the jenkins build log is printed, it becomes unrecognizable for Chinese
???
.
2. Deployment
Ours jenkins
is deployed in centos
the 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 jenkins
whether the character set encoding is correct utf-8
.
3.1 View system information code
For example, if your jenkins
address is http://localhost:8083
, then visit http://localhost:8083//systemInfo
to display the page of system information. (You can also click [System Management]-[Status Information]-[System Information] to view), as shown in the figure below:
In addition to the frame selection in the above picture, there is a variable at the bottom of this page that sun.jnu.encoding
is not correct utf-8
, obviously jenkins
the 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:
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 docker
the running, for 3.1
the encoding problem shown above, I added the things selected in the lower border to the startup script:
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 LANG
the 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.
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 export
or source
command to modify the variable, it will be invalid when you exit the container.
The third sentence is to ensure that 3.1 file.encoding
becomes utf-8
.
4.2 Modify LANG
parameters 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 jenkins
the build, the log has always been ???
this thing. I went to the position 3.2 above. Modified LANG
variables. As shown below:
5. Special instructions
Many small partners may docker
not be very clear about how the container looks at the code. You can follow the steps below.
If you don't modify it here, sometimes the default is en
the beginning, and sometimes it is POSIX
.
To set variables in the docker startup script, you need to -e
pass parameters, that is,
some people think that locale
setting variables under the previous command LC_ALL
can LC_*
change all the variables, but I haven't tried it.
The above are the problems I encountered and the solutions.