0

I installed jenkins ssh agent plugin. I created ssh private key on the linux server(using ssh-keygen -t rsa command) I am trying to connect. Then under jenkins credintials added SSH Username with private key with all required fields. In jenkinsfile added simple command to run over ssh:

pipeline {
   agent any
   stages {
       stage('---doingsomething---') {
            steps {
                sshagent (credentials: ['jbowner-195']) {
                    sh 'ssh -o StrictHostKeyChecking=no -l jbowner 10.10.23.195 uname -a'
                }
            }
       }

   }
}

When I press build button process is starting and never ending. No error, no timeout issue. Here is piece of output on which jenkins stacks

[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (---echoing---)
[Pipeline] sshagent
[ssh-agent] Using credentials jbowner (jbowner 10.10.23.195)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent]   Exec ssh-agent (binary ssh-agent on a remote machine)
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-XSQPEUHOqZQR/agent.10226
SSH_AGENT_PID=10229
Running ssh-add (command line suppressed)
Identity added: /home/jenkins/.jenkins/workspace/Eformgenerator-Prod@tmp/private_key_5151715321960722060.key (/home/jenkins/.jenkins/workspace/Eformgenerator-Prod@tmp/private_key_5151715321960722060.key)
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
+ ssh -o StrictHostKeyChecking=no -l jbowner 10.10.23.195 uname -a

any ideas?

gogagubi
  • 965
  • 1
  • 15
  • 36

1 Answers1

0

Jenkins ssh plugin didn't work for me. My solution is

  1. generate rsa keys on source machine using ssh-keygen -t rsa
  2. ssh-copy-id username@destination_ip. Then enter destination password. This will add as destination ip as a known host and adds source key on the destination machine as a authorized key.

then instead of using jenkins ssh agent I used standard ssh command like this.

pipeline {
   agent any
   stages {
       stage('---echoing---') {
            steps {
                sh 'ssh -o StrictHostKeyChecking=no jbowner@10.10.23.195 uptime'
            }
       }

   }
}

This is working because servers have been trusting each other using ssh key

gogagubi
  • 965
  • 1
  • 15
  • 36