Jenkins:同時使用 ssh-agent 和 git 插件

Jenkins:同時使用 ssh-agent 和 git 插件

所以,我有以下情況:每個專案都有專用使用者的伺服器(例如foo)和作為使用者運行的 jenkins 伺服器jenkins。我為我的用戶產生了一個 SSH 金鑰對foo,並將公共金鑰對作為部署金鑰新增至 github 儲存庫。 (我確認我可以與用戶克隆存儲庫foo

在 Jenkins 中,我在“管理 Jenkins”>“管理憑證”中將身份驗證設定為“帶有私鑰的 SSH 使用者名稱”,使用者名稱為“foo”,foo私鑰位於“全域”範圍內。

所以我用以下配置了我的詹金斯工作正確的工作空間(例如,顯然/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 (https://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) 機器上運作。

我在這裡缺少什麼?我提供的憑證似乎沒有被使用,這解釋了為什麼它會在權限上爆炸。但我不明白為什麼他們不被使用?為什麼不能使用git@URL?

由於它因權限問題而卡住,git init我在 中手動運行該操作,但重新運行 Jenkins 作業時,它又因權限問題而/home/foo/deployment卡住。git fetch

答案1

啊,是的,我真是太傻了。 SSH 使用者代理顯然只允許使用者jenkins連接到遠端儲存庫foo,但不授予其寫入本機檔案系統的權限...

相關內容