JenkinsにGitのPluginをインストールする方法
Jenkinsをインストールした後に入れておきたいプラグインの一つであるGitです。
JenkinsにGit Pluginをインストールする
最新のバージョン情報などは公式ページで確認してください。
- jenkinsの管理
- Pluginの管理
- git pで検索
- 再起動せずにインストールを選択
githubのアクセス権を確認する
鍵の登録をせずにjenkinsユーザで認証をしようとすると、以下の通り「Permission denied 」となってしまいます。
[root@localhost .ssh]# sudo -u jenkins ssh -T git@github.com Permission denied (publickey).
鍵の登録については以下で確認してください。
githubことはじめ<複数ユーザでpushするまでの初期設定> - ぽぽぽぽーんのネットワークとOSS
GitHubのコードをjenkinsで実行する
レポジトリのURLはhttps://ではなくgit@github:としてください。設定は直感的に簡単に設定可能です。ここでは実行するとコンソールにhelloworldと表示されるだけのPythonコードを実行する例を記載しておきます。
[root@localhost jenkins]# ls workspace/ Helloworld Helloworld-git [root@localhost jenkins]# ls workspace/Helloworld-git/ file.py hello.py LICENSE README.md
ビルドの実行した後のコンソール出力です。git configでupstreamを設定しgit fetchで差分取得をしていています。最終的にコンソールにhello worldが表示され、処理結果はSUCESSとなっています。エラーコードが1で返って来た場合にのみFailedとなります。エラー処理のさせる上で覚えておいた方がよいです。
Started by user anonymous Building in workspace /var/lib/jenkins/workspace/Helloworld-git > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url git@github.com:<username>/jenkins_cron.git # timeout=10 Fetching upstream changes from git@github.com:<username>/jenkins_cron.git > git --version # timeout=10 > git fetch --tags --progress git@github.com:<username>/jenkins_cron.git +refs/heads/*:refs/remotes/origin/* > git rev-parse refs/remotes/origin/master^{commit} # timeout=10 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10 Checking out Revision 532fdfa4a0fa4f0f5f441a572eef739f081e6522 (refs/remotes/origin/master) > git config core.sparsecheckout # timeout=10 > git checkout -f 532fdfa4a0fa4f0f5f441a572eef739f081e6522 > git rev-list fa47bd99555245dd6b24f1b87dae0c3faf03715e # timeout=10 [Helloworld-git] $ /bin/sh -xe /tmp/hudson4159611986054289808.sh + python hello.py hello world Finished: SUCCESS
次はjenkinsの継続的インテグレーションに関わる部分を書いておきたいと思います。
シェアして頂けると嬉しいです。
参考になったという方がいれば是非お願いしますm(_ _ )m
モチベーション維持の観点で非常に励みになります。
Jenkins実践入門 ?ビルド・テスト・デプロイを自動化する技術 (WEB+DB PRESS plus)
- 作者: 佐藤聖規,和田貴久,河村雅人,米沢弘樹,山岸啓,川口耕介
- 出版社/メーカー: 技術評論社
- 発売日: 2011/11/11
- メディア: 単行本(ソフトカバー)
- 購入: 26人 クリック: 496回
- この商品を含むブログ (64件) を見る
- 作者: Junio C Hamano,大塚弘記,川口耕介,kana,大竹智也(tomoya),尾藤正人,WEB+DB PRESS編集部
- 出版社/メーカー: 技術評論社
- 発売日: 2013/04/10
- メディア: 大型本
- クリック: 1回
- この商品を含むブログ (11件) を見る