简体   繁体   English

jenkins build-尝试执行包含ssh命令的shell命令

[英]jenkins build - trying to execute shell command that include ssh command

Background Information 背景资料

I'm trying to get jenkins to execute the following shell commands as a part of my build process: 我正在尝试让詹金斯执行以下shell命令,这是我的构建过程的一部分:

ssh root@10.111.11.11
rc-status

Right now it's failing with the following error message: 现在,它失败并显示以下错误消息:

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 root@10.111.11.11
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

What I've tried so far: 到目前为止,我已经尝试过:

Unfortunately, it doesn't seem to tell me the line number in the known_hosts file that it doesn't like. 不幸的是,它似乎并没有告诉我它不喜欢的known_hosts文件中的行号。 On the same server that jenkins is running on, I can successfully ssh into the remote server 10.111.11.11 with no errors from a command prompt. 在运行jenkins的同一服务器上,我可以成功将ssh成功插入远程服务器10.111.11.11,而不会出现命令提示符下的错误。

Could it be the fact that it's trying as "anonymous" instead of my id? 难道是它尝试使用“匿名”而不是我的ID的事实? If so, how do I resolve this? 如果是这样,我该如何解决? I can't see anything that allows me to specify what user to ssh as in jenkins. 我看不到任何可以像jenkins一样指定ssh用户的内容。

Thanks. 谢谢。

It is the host key verification that fails, not user authentication. 失败的是主机密钥验证,而不是用户身份验证。 You can either ensure that the host key is stored in the known_hosts file (typically ~/.ssh of the user the Jenkins is running as), eg 您可以确保主机密钥存储在known_hosts文件中(通常是以Jenkins身份运行的用户的~/.ssh ),例如

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

Or if you do not care about the security, you can disable the host key verification: 或者,如果您不关心安全性,则可以禁用主机密钥验证:

ssh -o StrictHostKeyChecking=no root@10.111.11.11

Other tips 其他技巧

If I got it right, you want to run command rc-status on the remote host. 如果我做对了,您想在远程主机上运行命令rc-status In that case, you should use ssh remote command execution, ie give the command as a parameter directly to the ssh: 在这种情况下,您应该使用ssh远程命令执行,即将命令作为参数直接提供给ssh:

ssh root@10.111.11.11 rc-status

For setting up the public key authentication I will recommend using SSH agent plugin . 对于设置公共密钥身份验证,我建议使用SSH代理插件 And if you have any further problems, it is always helpful to increase the ssh verbose level eg ssh -vvv ... 如果还有其他问题,增加ssh详细级别总是很有帮助的,例如ssh -vvv ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM