2015-09-15 78 views
1

我設置jenkins生成管道,並在其中一個生成步驟,我試圖克隆一個存儲庫。git克隆不工作在詹金斯外殼腳本

生成步驟(執行shell):

git clone [email protected]:orgname/reponame.git

它無法在此步驟與

10:14:01 Permission denied (publickey). 
10:14:01 fatal: The remote end hung up unexpectedly 
10:14:01 Build step 'Execute shell' marked build as failure 
10:14:01 Finished: FAILURE 

然而,在設置回購,我已設置單片機爲GIT中,並且已經指定存儲庫的網址爲git clone [email protected]:orgname/reponame.git,這完美地工作。

任何想法,我可能會在這裏失蹤。

+0

Jenkins作爲自己的用戶運行。您是否測試切換到Jenkins用戶並進行克隆? –

+0

在系統或github賬戶中切換用戶? – Anoop

+1

切換到系統上的jenkins用戶,並從命令行自己運行clone命令。你prolly沒有設置該用戶的github ssh的東西。 – Reck

回答

2

Github使用ssh公鑰/私鑰對進行身份驗證。當你使用github時,你需要提供你的公鑰。您可能已經這麼做了,繼these instructions之後。

當您生成密鑰對時,默認行爲是只有生成密鑰對的用戶纔有權訪問它。這意味着如果您將其生成爲upr,則用戶jenkins無法訪問連接到github所需的密鑰對。

要解決此問題,請切換至jenkins用戶。如果您在UNIX的時候,你可以通過

sudo su - jenkins 

做到這一點,然後按照keygeneration steps provided by github。對於Jenkins使用密鑰,最簡單的方法是使用無密碼創建密鑰。

我沒有使用它,但Jenkins plugin like this可能允許您使用密碼保護的密鑰對。

+1

你很想使用sudo su - jenkins:https://superuser.com/questions/453988/whats-the-difference-between-su-with-and-without-hyphen – Reck