Answers: <p>Found the problem:</p>
  
  <p>I was using the human readable key name from the GUI.
  Need to use the key's UUId ID instead (this is specified next to the name in credentials screen)</p>
  
  <pre><code>steps {
              sshagent ( ['THIS-SHOULD-HAVE-BEEN-A-UNIQUE-ID-INSTEAD-OF-A-NAME']) {
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2018-11-13T20:09:02.670Z
Answers: Would you be so kind as to show an example of the UUID in the GUI?
Answers: 2rs2ts
Answers: CC BY-SA 4.0
Answers: 2018-11-14T22:00:32.837Z
Answers: Project is no longer active, so I don't have a screenshot. However, when you dig around your credentials in your Jenkins configuration:  You will find configuration screen where your key has 2 attributes: It has a human readable name such as: "My_Dev_Credentials" which is displayed in most screens. But, it also has a unique id which should look something like a long hexadecimal string (which is garbage to humans). It should look something like: "571fe649-7844-4e93-891e-35496cc8cc72 " . Basically you should referemce that hex ID instead of the English name of your credentials. I hope that helps
Answers: eshalev
Answers: CC BY-SA 3.0
Answers: 2018-03-27T09:40:03.020Z
Answers: 2018-03-27T09:40:03.020Z
Answers: eshalev
Body: <p>I am new to Jenkinsfile.
  I have previously configured my Jenkins job from GUI, and we are now upgrading our server to use Jenkinsfile.
  My job contains a section which needs to SSH to another server.
  To do this, I previously used the sshagent plugin on the GUI to specify my keys.
  However, on the jenkinsfile mechanism this does not work.</p>
  
  <p>First things first:
  Aside from using jenkinsfile, we have also trasitioned to building in <strong>docker</strong>. I read in some places that docker might conflict with sshagent plugin, so I am trying to remove docker by starting a clean job with "agent any" and trying to test.</p>
  
  <p>So my new job looks like this:</p>
  
  <pre><code>    @NonCPS  // Necessary to allow .each to work.
  def changelist() {
      def changes = ""
      currentBuild.changeSets.each { set -&gt;
          set.each { entry -&gt;
              changes += "${entry.author.id} "
          }
      }
      changes
  }
  
  pipeline {
      agent none
      stages {
              stage('test') {
              agent any
              steps {
                  sshagent ( ['a-jenkins-credential']) {
      sh '''
  ssh -vv myuser@myserver echo testing connection || true
  ssh-add -L
  echo done running remote windows test
  '''
    }
              }
          }
  
  
  }
  }
  </code></pre>
  
  <p>On the same server, but <strong>using the jenkins GUI, this works flawlessly</strong>, but on the jenkinsfile pipeline this produces:</p>
  
  <pre><code>FATAL: [ssh-agent] Could not find specified credentials
  </code></pre>
  
  <p>and proceeds run and fail on the ssh command. The funny thing is, that this job uses the exact same key to succesfully pull from GIT, so it's not like it's not installed on the server. </p>
  
Tags: <jenkins><jenkins-pipeline><jenkins-plugins>
Title: sshagent and jenkinsfile
UserDisplayName: eshalev
ThreadText: # sshagent and jenkinsfile
  
  (Asked by: username_0 on 2018-03-27)
  
  I am new to Jenkinsfile.
  I have previously configured my Jenkins job from GUI, and we are now upgrading our server to use Jenkinsfile.
  My job contains a section which needs to SSH to another server.
  To do this, I previously used the sshagent plugin on the GUI to specify my keys.
  However, on the jenkinsfile mechanism this does not work.
  
  First things first:
  Aside from using jenkinsfile, we have also trasitioned to building in **docker**. I read in some places that docker might conflict with sshagent plugin, so I am trying to remove docker by starting a clean job with "agent any" and trying to test.
  
  So my new job looks like this:
  
  ```
      @NonCPS  // Necessary to allow .each to work.
  def changelist() {
      def changes = ""
      currentBuild.changeSets.each { set ->
          set.each { entry ->
              changes += "${entry.author.id} "
          }
      }
      changes
  }
  
  pipeline {
      agent none
      stages {
              stage('test') {
              agent any
              steps {
                  sshagent ( ['a-jenkins-credential']) {
      sh '''
  ssh -vv myuser@myserver echo testing connection || true
  ssh-add -L
  echo done running remote windows test
  '''
    }
              }
          }
  
  }
  }
  
  ```
  
  On the same server, but **using the jenkins GUI, this works flawlessly**, but on the jenkinsfile pipeline this produces:
  
  ```
  FATAL: [ssh-agent] Could not find specified credentials
  
  ```
  
  and proceeds run and fail on the ssh command. The funny thing is, that this job uses the exact same key to succesfully pull from GIT, so it's not like it's not installed on the server.
  
  **Tags:** jenkins, jenkins-pipeline, jenkins-plugins
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-03-27. Score: 10 | Accepted answer
  
  Found the problem:
  
  I was using the human readable key name from the GUI.
  Need to use the key's UUId ID instead (this is specified next to the name in credentials screen)
  
  ```
  steps {
              sshagent ( ['THIS-SHOULD-HAVE-BEEN-A-UNIQUE-ID-INSTEAD-OF-A-NAME']) {
  
  ```
  
  > **Comments:**
  > **username_1**: Would you be so kind as to show an example of the UUID in the GUI?  
  > **username_0**: Project is no longer active, so I don't have a screenshot. However, when you dig around your credentials in your Jenkins configuration:  You will find configuration screen where your key has 2 attributes: It has a human readable name such as: "My_Dev_Credentials" which is displayed in most screens. But, it also has a unique id which should look something like a long hexadecimal string (which is garbage to humans). It should look something like: "571fe649-7844-4e93-891e-35496cc8cc72 " . Basically you should referemce that hex ID instead of the English name of your credentials. I hope that helps  
  
  ---
  
  