Jenkinsのノードを追加してみよう!(Mac編)

ノードを追加することで、ジョブを複数のマシンで処理できるようになります。
Jenkins にジョブが溜まりはじめたら、ノードの追加を検討しましょう。

ここでは、ノードを追加する手順を説明します。

 

 

関連記事

スポンサーリンク

ノードの追加

  1. 左メニューの[Jenkinsの管理]をクリックします。
  2. ページを下にスクロールすると表示される[ノードの管理]をクリックします。
  3. 左メニューの[新規ノード作成]をクリックします。
  4. [ノード名]に[node01]と入力し、[Permanent Agent]にチェックをいれ、[OK]をクリックします。
  5. [認証情報]の[追加]をクリックし、プルダウンに表示される[Jenkins]をクリックします。
  6. 以下の設定を行い、[追加]をクリックします。
    項目 設定
    Domain グローバルドメイン
    種類 ユーザー名とパスワード
    ユーザー名 任意(sshログインで使用するユーザー名を指定してください)
    パスワード 上記の[ユーザー名]で指定したユーザーのパスワード

  7. [認証情報]の[- なし]をクリックし、前の項目で追加したユーザー名が表示された項目をクリックします。
  8. [認証情報]以外の設定を以下のように行い[保存]をクリックします。
    ※あとでいつでも変更することが可能です。

    項目 設定値
    同時ビルド数 1
    リモートFSルート 任意(指定したディレクトリ以下にslave.jarとworkspaceディレクトリが作成されます)
    ラベル
    用途 このスレーブをできるだけ利用する
    起動方法 SSH経由でUnixマシンのスレーブエージェントを起動
    ホスト 任意(ノードを起動するマシンのIPアドレスまたはホスト名を指定してください)
    Host Key Verification Strategy Manually trusted key Verification Strategy
    Require manual verification of initial connection チェックをいれる
    可用性 Keep this agent online as much as possible

  9. 左メニューの[Trust SSH Host Key]をクリックします。
  10. フィンガープリント確認画面が表示されます。[Yes]をクリックします。
  11. [Launch agent]をクリックします。
  12. 起動時のログが流れ Agent successfully connected and online と表示されることを確認します。

以上でノードの追加ができました。ジョブ毎に実行するノードの指定ができるので、効率よくジョブが実行できるように設定を行ってください。

補足

認証情報の種類

上記手順では「ユーザー名とパスワード」を選択しましたが、プルダウンから以下が指定可能です。

  • ユーザー名とパスワード
  • Docker Host Certificate Authentication
  • SSH ユーザー名と秘密鍵
  • Secret file
  • Secret text
  • 証明書

状況により「ユーザー名とパスワード」より「SSH ユーザー名と秘密鍵」を選択したほうが良い場面があるかと思います。適宜使い分けましょう。

Host Key Verification Strategy

[Host Key Verification Strategy]に[Known hosts file Verification Strategy]を設定した場合、ノード起動に失敗します。ログには以下の内容が出力されます。

[06/24/18 02:08:30] [SSH] :22とのSSHコネクションをオープン
/Users/Shared/Jenkins/.ssh/known_hosts [SSH] No Known Hosts file was found at /Users/Shared/Jenkins/.ssh/known_hosts. Please ensure one is created at this path and that Jenkins can read it.
Key exchange was not finished, connection is closed.
java.io.IOException: There was a problem while connecting to :22
	at com.trilead.ssh2.Connection.connect(Connection.java:834)
	at hudson.plugins.sshslaves.SSHLauncher.openConnection(SSHLauncher.java:1324)
	at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:831)
	at hudson.plugins.sshslaves.SSHLauncher$2.call(SSHLauncher.java:820)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Key exchange was not finished, connection is closed.
	at com.trilead.ssh2.transport.KexManager.getOrWaitForConnectionInfo(KexManager.java:95)
	at com.trilead.ssh2.transport.TransportManager.getConnectionInfo(TransportManager.java:237)
	at com.trilead.ssh2.Connection.connect(Connection.java:786)
	... 7 more
Caused by: java.io.IOException: The server hostkey was not accepted by the verifier callback
	at com.trilead.ssh2.transport.KexManager.handleMessage(KexManager.java:548)
	at com.trilead.ssh2.transport.TransportManager.receiveLoop(TransportManager.java:790)
	at com.trilead.ssh2.transport.TransportManager$1.run(TransportManager.java:502)
	... 1 more
[06/24/18 02:08:30] Launch failed - cleaning up connection
[06/24/18 02:08:30] [SSH] コネクション終了
[Known hosts file Verification Strategy]はマシン内にあるknown_hostsに記録済みのマシンのみ許可する設定です。ログに出力されているknown_hostsファイル(上記ログだと/Users/Shared/Jenkins/.ssh/known_hosts)に信頼した情報のみ記載するのが一番セキュアですので、[Host Key Verification Strategy]は用途に応じて適宜設定してください。

Twitterでフォローしよう

おすすめの記事