LoginSignup
8
10

More than 5 years have passed since last update.

jenkinsでサーバ構築ツール作成

Last updated at Posted at 2015-09-10

概要

周辺で脱jenkinsの流れを感じる今日このごろですが、昔jenkinsを環境構築ツールとして利用して結構便利だった記憶があるので思い出しながらもう一度作ってみようと思います。邪道jenkinsの精神です。

実現したいこと

  • ある環境が構築したくなったら、その構築ページにスッと行けてシュッと作れる
    • あのコマンドをどこで実行してその後にこれを実行して、、など記憶だよりを無くす
  • 黒い画面を出さなくても良くする
    • Webブラウザの操作だけで構築を完結させる

今はやらないこと

  • 構築リソース管理
    • 何が構築されているとか、構築可能なリソース(CPU,Memroy,HDD)がどれだけあるとか。

構造

  • 作りながら考える

インストール

これ を実行する。完全に自分用の覚え書き。

ログイン設定

  • アカウント作成

    • Jenkinsの管理 -> グローバルセキュリティの設定
      • セキュリティ有効化のチェックをクリック
      • アクセス制御 -> ユーザー情報 -> Jenkinsのユーザーデータベースを選択
        • ユーザーにサインアップを許可をチェック
      • アクセス制御 -> 権限管理
        • ログイン済みユーザーに許可をチェック
    • 保存をクリック
    • 右上のサインアップをクリック
    • ユーザー情報を入力してサインアップをクリック
  • セキュリティ有効化のオプションを変更

    • Jenkinsの管理 -> グローバルセキュリティの設定
      • アクセス制御 -> 権限管理
        • ログイン済みユーザーに許可をクリック
    • 保存をクリック

ログインしたユーザのみ操作可能になる

スクリーンショット 2015-08-31 7.45.02.png

参考

プラグインのアップデートと導入

  • アップデート
    • Jenkinsの管理 -> プラグインの管理
      • すべてのプラグインにチェックを入れる
        • ダウンロードして再起動後にインストールをクリック
  • Git Pluginの導入

    • 1.626はデフォルトでGitクライアントが入っている
    • Gitの設定
      • Jenkinsの管理 -> システムの設定
        • Git
          • Path to Git executableを /usr/bin/gitに変更
      • 保存をクリック
  • GitHub Pluginの導入

    • GitHub plugin
      • This plugin integrates Jenkins with Github projects.
    • GitHub API plugin
      • This plugin is a library plugin used by other GitHub related plugins to share the same libraries. This plugin does not have any user visible feature by itself. There's no need to install this plugin manually, although you want to keep it up to date.
    • Plain Credentials Plugin
      • Allows use of plain strings and files as credentials.
  • メモ

    • 後で使うかもしれないプラグインのメモ

      • Git server plugin
        • This plugin is a library plugin for other plugins to add git server functionality to Jenkins.
      • Github Authentication plugin
        • The GitHub Authentication Plugin provides a means of using GitHub for authentication and authorization to secure Jenkins. GitHub Enterprise is also supported.
      • Git Parameter Plug-In
        • This plugin allows you to choose between Git tags or sha1 of your SCM repository so Git Plugin installed is required.
      • Pry Plugin
        • This plugin lets you remotely inspect/alter running Jenkins instance through pry. Think of it as the Ruby version of the Groovy shell console
      • DigitalOcean plugin
        • Allow Jenkins to start slaves on DigitalOcean droplets on demand and destroy them as they get unused.
      • GitHub Pull Request Builder
        • This plugin builds pull requests in github and report results.

テスト実行

  • HelloWorldを表示する
    • 新規ジョブの作成
      • ジョブ名 : HelloWorld
      • フリースタイルプロジェクトのビルドをクリック
      • OKをクリック
    • ビルド
      • ビルド手順の追加
        • シェルの実行 -> シェルスクリプト
          • echo "HelloWorld"
      • 保存
    • ビルドの実行をクリック
    • ビルド履歴の#1をクリック
      • コンソール出力をクリック

スクリーンショット 2015-08-31 8.19.50.png

  • GitHubからCloneして実行
    • 新規ジョブの作成
      • ジョブ名 : gittest
      • フリースタイルプロジェクトのビルドをクリック
      • OKをクリック
    • ソースコード管理
    • ビルド
      • ビルド手順の追加
        • シェルの実行 -> シェルスクリプト
          • sh ${WORKSPACE}/adhoc/jenkins_test.sh
      • 保存
    • ビルドの実行をクリック
    • ビルド履歴の#1をクリック
      • コンソール出力をクリック

スクリーンショット 2015-08-31 11.23.48.png

  • [作成中] ansibleを実行
    • ssh秘密鍵を${JENKINS_HOME}/userContent 配下に置く
cd ${WORKSPACE}/adhoc
ansible-playbook -i "127.0.0.1," --extra-vars "ansible_user=ftakao2007" --private-key="${JENKINS_HOME}/userContent/id_rsa" playbook/ansible_test.yml -vvv

[作成中] バックアップ

トラブルシューティング

[SSH] Exception:Algorithm negotiation fail

[SSH] Exception:Algorithm negotiation fail
com.jcraft.jsch.JSchException: Algorithm negotiation fail
    at com.jcraft.jsch.Session.receive_kexinit(Session.java:520)
    at com.jcraft.jsch.Session.connect(Session.java:286)
    at com.jcraft.jsch.Session.connect(Session.java:150)
    at org.jvnet.hudson.plugins.SSHSite.createSession(SSHSite.java:141)
    at org.jvnet.hudson.plugins.SSHSite.executeCommand(SSHSite.java:151)
    at org.jvnet.hudson.plugins.SSHBuilder.perform(SSHBuilder.java:60)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
    at hudson.model.Build$BuildExecution.build(Build.java:205)
    at hudson.model.Build$BuildExecution.doRun(Build.java:162)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
    at hudson.model.Run.execute(Run.java:1741)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:410)
Build step 'Execute shell script on remote host using ssh' marked build as failure
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: FAILURE

対策

$ sudo vi /etc/ssh/sshd_config
============================================================
...
KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
============================================================

$ sudo systemctl restart sshd.service
8
10
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
8
10