diff --git a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java index 4bc7e94177..56404f006e 100644 --- a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java +++ b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java @@ -1464,6 +1464,12 @@ private String launchCommandWithCredentials(ArgumentListBuilder args, File workD env.put("GIT_SSH", ssh.getAbsolutePath()); env.put("SSH_ASKPASS", pass.getAbsolutePath()); + // supply a dummy value for DISPLAY if not already present + // or else ssh will not invoke SSH_ASKPASS + if (!env.containsKey("DISPLAY")) { + env.put("DISPLAY", ":"); + } + } else if (credentials instanceof StandardUsernamePasswordCredentials) { StandardUsernamePasswordCredentials userPass = (StandardUsernamePasswordCredentials) credentials; listener.getLogger().println("using GIT_ASKPASS to set credentials " + userPass.getDescription()); @@ -1558,7 +1564,10 @@ private String quoteUnixCredentials(String str) { private File createWindowsSshAskpass(SSHUserPrivateKey sshUser) throws IOException { File ssh = File.createTempFile("pass", ".bat"); try (PrintWriter w = new PrintWriter(ssh, Charset.defaultCharset().toString())) { - w.println("echo \"" + quoteWindowsCredentials(Secret.toString(sshUser.getPassphrase())) + "\""); + // avoid echoing command as part of the password + w.println("@echo off"); + // no need for quotes on windows echo -- they will get echoed too + w.println("echo " + Secret.toString(sshUser.getPassphrase())); w.flush(); } ssh.setExecutable(true);