Jenkins Pipeline PluginでWindows Batch Scriptを使うと文字化けする

  • またまた、Workflow PluginあらためPipeline Pluginの話です。
  • まあ、さもありなんとは思います。
    • build jobとかbatではないところは当然文字化けてません。
    • UTF-8にしてあげればいいんでしょうねと。
      • chcp 65001してあげることにした。
node('Windows') {
    build job: 'foo', parameters: [new StringParameterValue("branch", branch)]
    
    step ([$class: 'CopyArtifact',
        projectName: "foo",
        filter: "build/libs/*.jar",
        target: "foo/webapps/bar/WEB-INF/lib",
        fingerprintArtifacts: true,
        flatten: true
    ])
    
    bat 'chcp 65001'
    dir('webapp') {
        dirs = ["css", "images", "js"]
        dirs.each {
            bat "xcopy /Y /E /I .\\${it} ..\\foo\\webapps\\bar\\${it}"
        }
    }

これでchcp以降のxcopy等全てのbatが文字化しなくなりました。(なぜか英語で表示されるけど・・・)

Jenkins Pipeline PluginでRobocopyを使うと成功したのにFAILUREで返ってくる

  • Workflow PluginあらためPipeline Pluginを使い始めてます。便利だわー。Groovyだし。

実行したScript

node('Windows') {
    def snapshot = "${env.BUILD_TAG}"
    echo "$snapshot"
    bat "robocopy /E .\\foo \\\\server\\build\\Product\\${snapshot}\\foo"
}
  • これでrobocopyは成功してるのにFAILUREになってしまう。

修正

  • どうやらRobocopyは戻り値が0じゃないらしい

d.hatena.ne.jp

  • とりあえず0で返すようにしました。
node('Windows') {
    def snapshot = "${env.BUILD_TAG}"
    echo "$snapshot"
    bat """robocopy /E .\\foo \\\\server\\build\\Product\\${snapshot}\\foo
                if errorlevel 1 exit /b 0
                if errorlevel 0 exit /b 0"""
}

まあ、こんなもんか。

JIRAのグラフが文字化け(お豆腐)

おそらく日本語フォントだろう

  • ぐぐるとまさにズバリなのがあった

www.ricksoft.jp

対応

  • JIRAはJREを同梱しているのでインストールしたディレクトリのJREをいじる
    • fontconfig.btc, fontconfig.properties.srcには日本語設定が入っていないので以下のように対応した
$ cd /usr/local/jira/jre/lib
$ mv fontconfig.bfc fontconfig.bfc.org
$ mv fontconfig.properties.src fontconfig.properties.src.org
$ ln -s fontconfig.RedHat.6.bfc fontconfig.bfc
$ ln -s fontconfig.RedHat.6.properties.src fontconfig.properties.src
$ sudo aptitude search kochi
$ sudo aptitude install ttf-kochi-gothic ttf-kochi-mincho

上の記事はCentOS前提で、自分の環境はUbuntuだけどとりあえず文字化け直りました。(JIRAの再起動はいるけど)

Ubuntu 14.04 LTSで久々にaptitude使ったらppaのキーでエラーがでた

  • JIRAのインストールするのにまずaptitude updateしたら以下のようなエラーが出る。
W: GPG エラー: http://ppa.launchpad.net trusty InRelease: 公開鍵を利用できないため、以下の署名は検証できませんでした: NO_PUBKEY A123456789012345

対策

  • ぐぐると以下のようにキーをインポートしなさいというのが出るがうまくいかない。
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A123456789012345
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.c5xClbKCDL --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver keyserver.ubuntu.com --recv-keys A123456789012345
gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com
gpgkeys: key A123456789012345 can't be retrieved
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
  • どうやらkeyserverはデフォルトでは80番以外を使うので80番を指定するらしい。あとproxyサーバを指定するがうまくいかない。
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy=http://proxy.example.com:8080/ --recv-keys A123456789012345
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.R94qsVmLPa --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80 --keyserver-options http-proxy=http://proxy.example.com:8080/ --recv-keys A123456789012345
gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com
gpgkeys: key A123456789012345 can't be retrieved
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
  • 手当たり次第にキーサーバのミラーを試してみたらうまくいった。何なんだ・・・。
$ sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --keyserver-options http-proxy=http://proxy.example.com:8080/ --recv-keys A123456789012345
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.aaFL8YVkoC --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://pgp.mit.edu:80 --keyserver-options http-proxy=http://proxy.example.com:8080/ --recv-keys A123456789012345
gpg: requesting key EEA14886 from hkp server pgp.mit.edu
gpg: key EEA14886: public key "Launchpad VLC" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

JIRAをインストール(DBをPostgreSQLに作成)

JIRAのDBをPostgreSQLに作る

  • DB作るところは公式ドキュメントと若干変えているので忘れないようにメモ

PostgreSQLにユーザ(ROLE)を作る

  • ロールの作り方は公式ドキュメントに書いてなかったけどBitbucket Server(旧Stash)に合わせて作った。
postgres=# CREATE ROLE jiradbuser WITH PASSWORD 'xxxxxxxxxxxx';
CREATE ROLE
postgres=# ALTER ROLE jiradbuser LOGIN;
ALTER ROLE
postgres=# \du
                              List of roles
 Role name  |                   Attributes                   | Member of
------------+------------------------------------------------+-----------
 jiradbuser |                                                | {}
 postgres   | Superuser, Create role, Create DB, Replication | {}
 stash      |                                                | {}

PostgreSQLにデータベースを作る

  • 公式ドキュメントだとownerを指定してないけどせっかくロールを作ったので指定しておく。
postgres=# CREATE DATABASE jiradb WITH ENCODING 'UNICODE' LC_COLLATE 'C' LC_CTYPE 'C' TEMPLATE template0 OWNER=jiradbuser;
CREATE DATABASE
postgres=# \l
                                   List of databases
   Name    |   Owner    | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+------------+----------+-------------+-------------+-----------------------
 jiradb    | jiradbuser | UTF8     | C           | C           |
 postgres  | postgres   | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 |
 stash     | stash      | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 |
 template0 | postgres   | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |            |          |             |             | postgres=CTc/postgres
 template1 | postgres   | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |            |          |             |             | postgres=CTc/postgres
(5 rows)

参考

Jettyで動いている複数のアプリをNginxで1サイトのパスに紐付ける

背景

  • 訳あって複数のアプリをJettyのプロセスを分けて動かしてます。
    • 1アプリ=1Jettyプロセスになっていて複数のアプリがあります。理由があってやってるのでこれはしかたがない。
    • そうするとポート番号がいっぱい増えて分かりにくいので80番にまとめたい。
    • まあ、オンプレのシステムなんですけどね・・・。
    • こんな感じ
http://example.com:8081/context/ → http://example.com/context/1/
http://example.com:8082/context/ → http://example.com/context/2/
http://example.com:8083/context/ → http://example.com/context/3/

設定でハマった所

  • Nginxのリバースプロキシを設定するときにproxy_passのところでJettyのContextPathとlocationのパスが違ってもいいのかと思っていたんですが、どうも合わせないと上手く動きませんでした。
    • rewriteとか使えば別のやり方でもいけるのかもしれないですが、できればrewriteはあんまり使いたくないし。

Nginxの設定

  • 元々のJettyのContextPathと違う値なので注意。(後でJettyの設定でこちらに合わせる)
http {
  upstream context_1 {
    server 127.0.0.1:8081;
  }
  upstream context_2 {
    server 127.0.0.1:8082;
  }
  upstream context_3 {
    server 127.0.0.1:8083;
  }

  server {
    location /context/1/ {
      proxy_pass      http://context_1/context/1/
      proxy_redirect  default;
    }
    location /context/2/ {
      proxy_pass      http://context_2/context/2/
      proxy_redirect  default;
    }
    location /context/3/ {
      proxy_pass      http://context_3/context/3/
      proxy_redirect  default;
    }
}

Jettyの設定

  • ContextPathをNginxの設定に合わせる。
    • webappsにcontext.xmlを作成(webapps配下にあるcontext名とxml名を合わせてあります)
    • Warは使ってないのでresourceBaseで設定してます。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="contextPath">/context/1</Set>
    <Set name="resourceBase"><Property name="jetty.webapps" default="."/>/context</Set>
</Configure>
  • この設定を全部のJettyにしておく。

これでやりたいことが出来ました!(書くとたいしたことないけど結構ハマったのだ)

C# で製品バージョンとかファイルバージョンをAssemblyInfoから取得する

C#でコマンド作っててUsageの表示でバージョンとか出したいけど、AssemblyInfo.csに書いてあることを2度書きたくなかったので

  • Command Line Parser Libraryを使ってUsageを表示しているので、その中でアセンブリ情報を取得して表示します。

製品バージョンとファイルバージョン

  • 意外と簡単。
using System.Reflection;
using System.Diagnostics;

FileVersionInfo ver = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
help.Heading = new HeadingInfo(
          string.Format("foo Ver. {0} (File Ver. {1})", ver.ProductVersion, ver.FileVersion));

Copyright

  • 若干わかりにくい
using System.Reflection;

AssemblyCopyrightAttribute copyright = Assembly.GetExecutingAssembly().GetCustomAttributes(
               typeof(AssemblyCopyrightAttribute), false)[0] as AssemblyCopyrightAttribute;
help.Copyright = copyright.Copyright;

全体

using CommandLine;
using CommandLine.Text;

[HelpOption]
public string GetUsage()
{
    var help = new HelpText();

    FileVersionInfo ver = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
    help.Heading = new HeadingInfo(string.Format("foo Ver. {0} (File Ver. {1})", ver.ProductVersion, ver.FileVersion));

    AssemblyCopyrightAttribute copyright = Assembly.GetExecutingAssembly().GetCustomAttributes(
              typeof(AssemblyCopyrightAttribute), false)[0] as AssemblyCopyrightAttribute;
    help.Copyright = copyright.Copyright;

    help.AddDashesToOption = true;

    help.AddPreOptionsLine("Usage: foo [ -a/--aaa | -b/--bbb ]");

    return help;
}
  • この辺を参考にしました

u-prog.cocolog-nifty.com