Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Commit

Permalink
JENKINS-44050: Git SSH credentials are not passed to the plugin
Browse files Browse the repository at this point in the history
Fixed SSH credentials handling (private key was not passed to the
plugin)
  • Loading branch information
Stanley authored and Stanley committed May 5, 2017
1 parent e7e7daa commit 72b5182
Showing 1 changed file with 7 additions and 0 deletions.
Expand Up @@ -84,6 +84,7 @@ public class UnleashMavenBuildWrapper extends BuildWrapper {
private static String ENV_VAR_SCM_USERNAME = "UNLEASH_SCM_USERNAME";
private static String ENV_VAR_SCM_PASSWORD = "UNLEASH_SCM_PASSWORD";
private static String ENV_VAR_SCM_SSH_PASSPHRASE = "UNLEASH_SCM_SSH_PASSPHRASE";
private static String ENV_VAR_SCM_SSH_PRIVATE_KEY = "UNLEASH_SCM_SSH_PRIVATE_KEY";

private String goals = DescriptorImpl.DEFAULT_GOALS;
private String profiles = DescriptorImpl.DEFAULT_PROFILES;
Expand Down Expand Up @@ -222,6 +223,7 @@ private Map<String, String> updateCommandWithScmCredentials(AbstractBuild build,
String scmUsername = null;
String scmPassword = null;
String scmSshPassphrase = null;
String scmSshPrivateKey = null;
if (StringUtils.isNotBlank(this.credentialsId)) {
StandardUsernameCredentials credentials = CredentialsProvider.findCredentialById(this.credentialsId,
StandardUsernameCredentials.class, build, URIRequirementBuilder.create().build());
Expand All @@ -233,6 +235,7 @@ private Map<String, String> updateCommandWithScmCredentials(AbstractBuild build,
SSHUserPrivateKey c = (SSHUserPrivateKey) credentials;
Secret passphrase = c.getPassphrase();
scmSshPassphrase = passphrase != null ? passphrase.getPlainText() : null;
scmSshPrivateKey = c.getPrivateKey();
}
}

Expand All @@ -249,6 +252,10 @@ private Map<String, String> updateCommandWithScmCredentials(AbstractBuild build,
command.append(" -Dunleash.scmSshPassphraseEnvVar=" + ENV_VAR_SCM_SSH_PASSPHRASE);
scmEnv.put(ENV_VAR_SCM_SSH_PASSPHRASE, scmSshPassphrase);
}
if (scmSshPrivateKey != null) {
command.append(" -Dunleash.scmSshPrivateKeyEnvVar=" + ENV_VAR_SCM_SSH_PRIVATE_KEY);
scmEnv.put(ENV_VAR_SCM_SSH_PRIVATE_KEY, scmSshPrivateKey);
}
return scmEnv;
}

Expand Down

0 comments on commit 72b5182

Please sign in to comment.