jenkins yes Java Developed applications , A lot of things can go through -D Pass in options to set , This article takes the adjustment of Chinese disorder code as an example , To illustrate how common changes can be made .

phenomenon

use jenkinsfile Pipeline defined , If stage When the name is Chinese , No problem with graphic display , But in console The output of will be displayed as ?? The content of random code .

The display of the content of the garbled code is because the pipeline definition code contains Chinese information, such as :
stage(" Branch content pull ") { steps { ...
reason

Relevant settings can be confirmed by system information , Coding information and file.encoding relevant , After confirmation, it is found that the coding method is not utf8 Caused by ( It needs to confirm whether the setting information is effective or not )


Modification method

Either way , In the end, it's all going to start jenkins On parameter passing of , Like through JAVA_OPTS, The settings are as follows

Settings Set value
file.encoding UTF-8
sun.jnu.encoding UTF-8
Modify the startup script directly , stay java Add directly after -D Options may be the most direct way , Or through Jenkins Setting environment variables in , Indirectly affect settings .
/ # ps |grep java 9 root 0:50 java -jar -Duser.timezone=Asia/Shanghai -Dsun.jnu
.encoding=UTF-8 -Dfile.encoding=UTF-8 -Dhudson.model.DirectoryBrowserSupport.CSP
= /usr/share/jenkins/jenkins.war 177 root 0:00 grep java / #
Setting confirmation



Result confirmation

Execute again job,console The Chinese content in the message can be displayed correctly

But the previous implementation job Of console Information will not change