Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #207 from matthauck/windows-askpass
[JENKINS-20356] Fix SSH_ASKPASS on windows
  • Loading branch information
MarkEWaite committed Feb 27, 2017
2 parents f52e3e8 + 8297db9 commit 9c12a00
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9c12a00

Please sign in to comment.