title: Jenkins pipeline - use ssh agent to clone a repository in another machine through ssh
body: <p>Use case:
  I have a Jenkins pipeline to update my development environment.
  My dev env is an EC2 aws instance with docker compose.</p>
  
  <p>The automation was written along the lines of:</p>
  
  <pre><code>withAWS(profile: 'default') {
     sh "ssh -o StrictHostKeyChecking=no -i ~/my-key.pem user@$123.456.789 /bin/bash -c 'run some command like docker pull'"
  }
  </code></pre>
  
  <p>Now, I have other test environments, and they all have some sort of docker-compose file, configurations and property files that requires me to go over all of them when something needs to change.</p>
  
  <p>To help with that, I created a new repository to keep all the different environment configurations, and my plan is to have a clone of this repo in all my development and test environments, so when I need to change something, I can just do it locally, push it, and have my jenkins pipeline update the repository in whichever environment it is updating.</p>
  
  <p>My jenkins has a ssh credential for my repo (it uses in another job that clones the repo and run tests on source code), so I want to use that same credential.</p>
  
  <p>Question: can I somehow, through ssh'ing into another machine, use Jenkins ssh-agent credentials to clone/update a bitbucket repository?</p>
  
  <p>Edit:
  I changed the pipeline to:</p>
  
  <pre><code>script {
     def hgCommand = "hg clone ssh://hg@bitbucket.org/my-repo"
     sshagent(['12345']) {
       sh "ssh -o StrictHostKeyChecking=no -i ~/mykey.pem admin@${IP_ADDRESS} /bin/bash -c '\"${hgCommand}\"'"
     }
  }
  </code></pre>
  
  <p>And I am getting:</p>
  
  <pre><code>[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-FOburguZZlU0/agent.662
  SSH_AGENT_PID=664
  Running ssh-add (command line suppressed)
  Identity added: /home/jenkins/workspace/abc@tmp/private_key_12345.key (rsa w/o comment)
  [ssh-agent] Started.
  [Pipeline] {
  [Pipeline] sh
  [test-env-config] Running shell script
  + ssh -o StrictHostKeyChecking=no -i /home/jenkins/mykey.pem admin@123.456.789 /bin/bash -c "hg clone ssh://hg@bitbucket.org/my-repo"
  remote: Warning: Permanently added the RSA host key for IP address '765.432.123' to the list of known hosts.
  remote: Permission denied (publickey).
  abort: no suitable response from remote hg!
  $ ssh-agent -k
  unset SSH_AUTH_SOCK;
  unset SSH_AGENT_PID;
  echo Agent pid 664 killed;
  [ssh-agent] Stopped.
  </code></pre>