2016-06-09 82 views
1

背景信息詹金斯建設 - 試圖執行shell命令,其中包括SSH命令

我試圖讓詹金斯作爲我的生成過程中的一部分執行以下shell命令:

ssh [email protected] 
rc-status 

現在它的失敗,出現以下錯誤信息:

Started by user anonymous 
Building in workspace /var/lib/jenkins/jobs/Ansible Repo/workspace 
> git rev-parse --is-inside-work-tree # timeout=10 
Fetching changes from the remote Git repository 
> git config remote.origin.url http://git.core.myinternaldomain.net/cgit/ansible.git/ # timeout=10 
Fetching upstream changes from http://git.core.myinternaldomain.net/cgit/ansible.git/ 
> git --version # timeout=10 
using .gitcredentials to set credentials 
> git config --local credential.username git # timeout=10 
> git config --local credential.helper store --file=/tmp/git805322146950822569.credentials # timeout=10 
> git -c core.askpass=true fetch --tags --progress http://git.myinternaldomain.net/cgit/ansible.git/ +refs/heads/*:refs/remotes/origin/* 
> git config --local --remove-section credential # timeout=10 
> git rev-parse refs/remotes/origin/dev^{commit} # timeout=10 
> git rev-parse refs/remotes/origin/origin/dev^{commit} # timeout=10 
Checking out Revision 3cf34f240632e3296793c130f4589fbceb37f5bf (refs/remotes/origin/dev) 
> git config core.sparsecheckout # timeout=10 
> git checkout -f 3cf34f240632e3296793c130f4589fbceb37f5bf 
> git rev-list 3cf34f240632e3296793c130f4589fbceb37f5bf # timeout=10 
[workspace] $ /bin/sh -xe /tmp/hudson50385520935510733.sh 
+ ssh [email protected] 
Pseudo-terminal will not be allocated because stdin is not a terminal. 
Host key verification failed. 
Build step 'Execute shell' marked build as failure 
Finished: FAILURE 

我試過到目前爲止:

不幸的是,它似乎沒有告訴我known_hosts文件中它不喜歡的行號。 在運行jenkins的同一臺服務器上,我可以成功從遠程服務器10.111.11.11 ssh中,在命令提示符下沒有錯誤。

難道這是事實,它試圖作爲「匿名」,而不是我的ID? 如果是這樣,我該如何解決這個問題?我看不到任何可以讓我指定用戶作爲jenkins中的ssh的東西。

感謝。

回答

5

這是主機密鑰驗證失敗,而不是用戶驗證。您可以確保主機密鑰存儲在known_hosts文件(通常爲運行Jenkins的用戶的~/.ssh)中,例如,

ssh-keyscan 10.111.11.11 >> ~/.ssh/known_hosts 

或者,如果你不關心安全性,您可以禁用主機密鑰驗證:

ssh -o StrictHostKeyChecking=no [email protected] 

其他提示

如果我這樣做是正確,你想運行命令在遠程主機上。在這種情況下,你應該使用ssh遠程命令執行,即給出命令直接到SSH參數:

ssh [email protected] rc-status 

有關設置公鑰認證,我會建議使用SSH agent plugin。如果還有其他問題,增加ssh詳細級別總是有幫助的,例如ssh -vvv ...

+0

你好。我怎麼知道用戶詹金斯運行的是什麼?對不起,這對詹金斯來說實際上就是我的第一天,我也對系統管理員的東西感到厭煩。我是一個低級程序員,試圖介紹ci – Happydevdays

+0

有很多方法。例如。您可以在shell步驟中運行命令'whoami'。 – jil

+0

我認爲ssh-agent正是我​​現在需要的。我會看看。謝謝。 – Happydevdays