jenkins亂碼問(wèn)題

jenkins

在此使用docker直接啟動(dòng)jenkins。

jenkins的docker地址為:https://hub.docker.com/r/jenkins/jenkins, 而排在第一位的版本太老,很多插件都不支持。不建議使用。

啟動(dòng)

docker run -d --name jenkins -p 8080:8080 -p 50000:50000 jenkins/jenkins:2.210-centos

然后通過(guò)訪問(wèn):http://localhost:8080, 按其提示操作即可。

控制臺(tái)亂碼問(wèn)題

在成功安裝后,運(yùn)行命令發(fā)現(xiàn)控制臺(tái)打印的中文為亂碼。

試遍目前網(wǎng)上所有方案,都無(wú)效

查看jenkins系統(tǒng)信息,其編碼仍然為ANSI_X3.4-1968

查看其Dockerfile,

image.png

見(jiàn)其啟動(dòng)命令為:/usr/local/bin/jenkins.sh,查看該腳本內(nèi)容,見(jiàn)如下內(nèi)容:

# if `docker run` first argument start with `--` the user is passing jenkins launcher arguments
if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then

  # read JAVA_OPTS and JENKINS_OPTS into arrays to avoid need for eval (and associated vulnerabilities)
  java_opts_array=()
  while IFS= read -r -d '' item; do
    java_opts_array+=( "$item" )
  done < <([[ $JAVA_OPTS ]] && xargs printf '%s\0' <<<"$JAVA_OPTS")

  readonly agent_port_property='jenkins.model.Jenkins.slaveAgentPort'
  if [ -n "${JENKINS_SLAVE_AGENT_PORT:-}" ] && [[ "${JAVA_OPTS:-}" != *"${agent_port_property}"* ]]; then
    java_opts_array+=( "-D${agent_port_property}=${JENKINS_SLAVE_AGENT_PORT}" )
  fi

因此在該腳本中設(shè)置JAVA_OPTS即可,在上面if語(yǔ)句前設(shè)置,內(nèi)容如下:

export JAVA_OPTS="-Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8"

重啟jenkins后生效:docker restart jenkins。 重新登錄后見(jiàn)file.encodingsun.jnu.encoding終于變?yōu)?code>UTF-8,至此測(cè)試打印中文生效:

image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容