自宅にGitLabとJenkinsを構築したんですが、超ハマりました。
ググってもなかなかそのものズバリの解が見つからずかなり悩んだので
同じ問題で躓いた誰かの一助になれば幸いだと思いここに記録をのこしておきます。
GitLabのバージョンは6.4.2です。Gitoliteは使わずにGitLab Shellの1.7.9を使っています。
jenkinsのバージョンは今回あまり重要ではなかったので適当に。
構築の手順などはググれば出てくるので省略しますがGitLabとjenkinsを同じサーバにインストールしています。
一通り構築が終わってプロジェクトをGitLabに登録してクライアントからソースのコミットやプッシュができるのを確認し終えてjenkinsでビルドをしようとしたとこから。
秘密鍵を使ってSSHによる接続をするための設定をしました。
伏字ですけどこんな感じ。
GitLabには公開鍵を登録してあります。
ここまでやってJenkinsでビルドを実行するとこんなエラーが。
Fetching changes from the remote Git repository Fetching upstream changes from xxx@サーバ:ユーザ/プロジェクト.git using GIT_SSH to set credentials FATAL: Failed to fetch from xxx@サーバ:ユーザ/プロジェクト.git hudson.plugins.git.GitException: Failed to fetch from xxx@サーバ:ユーザ/プロジェクト.git at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:623) at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:855) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:880) at hudson.model.AbstractProject.checkout(AbstractProject.java:1411) at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:651) at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:560) at hudson.model.Run.execute(Run.java:1670) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:231) Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress xxx@サーバ:ユーザ/プロジェクト.git +refs/heads/*:refs/remotes/origin/*" returned status code 128: stdout: stderr: Access denied. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
それで19行目に出ているステータスコード128でいろいろ調べてみたんだが、
これが原因がいろいろありすぎてなかなか分からない。
SSHKeyを作りなおして再登録したり、ユーザのアクセス権を見直したり、restoreconを打ってみたりとうんうん数時間あれやこれやと試行錯誤。大体においてこういうときは何をやっても上手くいかないもんで一向に解決しないのでちょっとゲームでもして気分転換をしたところはっとひらめいた。
結論としてはgitlab-shellの設定がダメだった。
# GitLab user. git by default user: git # Url to gitlab instance. Used for api calls. Should end with a slash. gitlab_url: "http://127.0.0.1:80/"
# GitLab user. git by default user: git # Url to gitlab instance. Used for api calls. Should end with a slash. gitlab_url: "http://127.0.0.1:8080/"
何のことはない。リバースプロキシから8080番に飛ばすためにポート番号を変えていたのにGitLab Shellの対応をしてなかったということでした。別PCをクライアントにしてしか使ってなかったのでなかなか気づけませんでした。
しかしもうちょっとエラーメッセージが分かり易くできそうなものですけどね。