0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows上のJenkinsでUTF-8のコーンソール出力を文字化けさせない方法(chcpしたくない)

Posted at

モチベーション

文字コード設定のためにchcp 65001とかのコマンドをビルドステップに入れたくない
でもコンソール出力にはUTF-8が文字化けなく表示されてほしい

想定

実行エージェントもJenkinsもWindows上で動いている

手順

  1. C:\Program Files\Jenkins\jenkins.xmlで環境変数にJAVA_TOOL_OPTIONSを追加

     <service>
       <id>jenkins</id>
       <name>Jenkins</name>
       <description>This service runs Jenkins automation server.</description>
       <env name="JENKINS_HOME" value="%ProgramData%\Jenkins\.jenkins"/>
    +  <env name="JAVA_TOOL_OPTIONS" value="-Dfile.encoding=UTF-8"/>
       <executable>C:\Program Files\Microsoft\jdk-17.0.15.6-hotspot\\bin\java.exe</executable>
       <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "C:\Program Files\Jenkins\jenkins.war" --httpPort=8082 --webroot="%ProgramData%\Jenkins\war"</arguments>
       <logmode>rotate</logmode>
     
       <onfailure action="restart"/>
       
       <extensions>
         <extension enabled="true" className="winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension" id="killOnStartup">
           <pidfile>%ProgramData%\Jenkins\jenkins.pid</pidfile>
           <stopTimeout>10000</stopTimeout>
           <stopParentFirst>false</stopParentFirst>
         </extension>
       </extensions>
    </service>
    
  2. Jenkins/実行エージェントの環境変数にJAVA_TOOL_OPTIONSを定義

    image.png


以上の設定でJenkinsのビルド結果のコンソール出力に文字化けがないことを確認した

UTF-8文字化け回避確認時のジョブ

  • シェル中にchcp 65001指定なし
  • フリースタイルジョブのシェルの実行
  • UTF-8の文字列を含んだシェルスクリプトのechoを呼び出し

Jenkinsのバージョンは2.504.3

エージェントのPCのシステム情報を確認するに以下の値で文字化けしなかったのでおそらく設定不要

エージェントPCのシステム情報システムプロパティの各値

  • native.encoding - MS932
  • sun.io.unicode.encoding - MS932
  • sun.stderr.encoding - ms932
  • sun.stdout.encoding - ms932

コンソール出力じゃないならこれらの値どこに影響するのかという疑問が残る…

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?