Configure known hosts for ssh during agent-side checkout
authorDmitry Neverov <dmitry.neverov@gmail.com>
Tue, 12 Dec 2017 10:47:55 +0000 (11:47 +0100)
committerDmitry Neverov <dmitry.neverov@gmail.com>
Tue, 12 Dec 2017 10:47:55 +0000 (11:47 +0100)
git-agent/src/jetbrains/buildServer/buildTriggers/vcs/git/agent/JSchClient.java

index 31ef9707c5eec603841c7d7cb01fee55875ee3c9..abec972a55bcd15d8990a4d22abf541107e25c46 100644 (file)
@@ -132,6 +132,20 @@ public class JSchClient {
 
       if (Boolean.parseBoolean(System.getenv(GitSSHHandler.SSH_IGNORE_KNOWN_HOSTS_ENV))) {
         session.setConfig("StrictHostKeyChecking", "no");
+      } else {
+        String userHome = System.getProperty("user.home");
+        if (userHome != null) {
+          File homeDir = new File(userHome);
+          File ssh = new File(homeDir, ".ssh");
+          File knownHosts = new File(ssh, "known_hosts");
+          if (knownHosts.isFile()) {
+            try {
+              jsch.setKnownHosts(knownHosts.getAbsolutePath());
+            } catch (Exception e) {
+              myLogger.log(Logger.WARN, "Failed to configure known hosts: '" + e.toString() + "'");
+            }
+          }
+        }
       }
 
       session.connect();