2016-06-09 84 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