
つまり、次のような状況です。プロジェクトごとに専用ユーザーを持つサーバー (例foo
) と、ユーザーとして実行される Jenkins サーバーですjenkins
。ユーザー用に SSH キー ペアを生成しfoo
、公開キーをデプロイ キーとして github リポジトリに追加しました。(ユーザーでリポジトリをクローンできることを確認しましたfoo
)
Jenkins では、「Jenkins の管理」>「資格情報の管理」で、ユーザー名「foo」と「グローバル」スコープの秘密鍵を使用して、「秘密鍵を持つ SSH ユーザー名」として認証を設定しましfoo
た。
そこで私はJenkinsジョブを次のように設定しました。正しいワークスペース(例えば、/home/foo/deployment
ユーザーが完全に所有権を持つfoo
)そして資格情報「foo」を使用する「ソースコード管理」では、リポジトリのSSH URLを使用したいと考えていました(例:[メールアドレス]:foo/foo.git) ただし、権限の問題があることがすぐに通知されます。
Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h [email protected]:foo/foo.git HEAD" returned status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
httpsバージョンのURL(github.com/foo/foo.git より) エラーは消えますが、ジョブを実行するとコンソール出力に次のエラーが表示されます。
Started by user developer
[EnvInject] - Loading node environment variables.
Building in workspace /home/foo/deployment
Cloning the remote Git repository
Cloning repository https://github.com/foo/foo.git
> git init /home/foo/deployment # timeout=10
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init /home/foo/deployment
[long stacktrace]
Caused by: hudson.plugins.git.GitException: Command "git init /home/foo/deployment" returned status code 1:
stdout:
stderr: /home/foo/deployment/.git: Permission denied
[long stacktrace]
ERROR: null
Finished: FAILURE
キー ペアはパスフレーズを使用しませんが、これが最初に機能するようになったらパスフレーズを追加したいと思います。Jenkins は、Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-65-generic x86_64) ボックスで実行されます。
ここで何が欠けているのでしょうか? 提供した資格情報が使用されていないようです。これが、権限で爆発する理由です。しかし、なぜ使用されていないのか理解できません。また、なぜ URL を使用できないのでしょうかgit@
?
で権限の問題により停止するため、 でgit init
手動で実行しました/home/foo/deployment
が、Jenkins ジョブを再実行すると で停止しgit fetch
、再び権限の問題が発生します。
答え1
ああ、そう、私はとても愚かでした。SSH ユーザー エージェントは、明らかに、ユーザーにjenkins
としてリモート リポジトリへの接続のみを許可しますfoo
が、ローカル ファイル システムへの書き込み権限は付与しません...