jenkins yesJava 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

Usejenkinsfile Pipeline defined, Ifstage When the name is Chinese, No problem with graphic display, But inconsole 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 andfile.encoding Relevant, After confirmation, it is found that the coding method is notutf8 Result in( It needs to confirm whether the setting information is effective or not)


Modification method

Either way, In the end, it's all going to startjenkins On parameter passing of, For example, throughJAVA_OPTS, The settings are as follows

Setting item Set value
file.encoding UTF-8
sun.jnu.encoding UTF-8
Modify the startup script directly, stayjava Add directly after-D Options may be the most direct way, Or throughJenkins 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 / #
Set confirmation



Result confirmation

Re executionjob,console The Chinese content in the message can be displayed correctly

But the previous implementationjob Ofconsole Information will not change