Happydevdays Happydevdays - 1 year ago 495
Bash Question

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:

ssh root@

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@
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.
On the same server that jenkins is running on, I can successfully ssh into the remote server with no errors from a command prompt.

Could it be the fact that it's trying as "anonymous" instead of my 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.


jil jil
Answer Source

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), e.g.

ssh-keyscan >> ~/.ssh/known_hosts

Or if you do not care about the security, you can disable the host key verification:

ssh -o StrictHostKeyChecking=no root@

Other tips

If I got it right, you want to run command rc-status on the remote host. In that case, you should use ssh remote command execution, i.e. give the command as a parameter directly to the ssh:

ssh root@ rc-status

For setting up the public key authentication I will recommend using SSH agent plugin. And if you have any further problems, it is always helpful to increase the ssh verbose level e.g. ssh -vvv ...