Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-74836] Allow using a file based ssh credential via system property #1003

Merged
Merged
Prev Previous commit
Next Next commit
more user friendly
  • Loading branch information
mikecirioli committed Nov 8, 2024
commit 83f632b5f94bed88eb7390f68f44222852fff0c6
17 changes: 17 additions & 0 deletions src/main/java/hudson/plugins/ec2/EC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,7 @@ public FormValidation doCheckSshKeysCredentialsId(@AncestorInPath ItemGroup cont
String privateKey;

if (System.getProperty(SSH_PRIVATE_KEY_FILEPATH, "").isEmpty()) {
// not using a static ssh key file
if (value == null || value.isEmpty()) {
return FormValidation.error("No ssh credentials selected");
}
Expand Down Expand Up @@ -1182,6 +1183,14 @@ public FormValidation doCheckSshKeysCredentialsId(@AncestorInPath ItemGroup cont
if (!hasEnd)
return FormValidation
.error("The private key is missing the trailing 'END RSA PRIVATE KEY' marker. Copy&paste error?");

if (System.getProperty(SSH_PRIVATE_KEY_FILEPATH, "").isEmpty()) {
if (!StringUtils.isEmpty(value)) {
return FormValidation.ok("Using private key file instead of selected credential");
} else {
return FormValidation.ok("Using private key file");
}
}
return FormValidation.ok();
}

Expand Down Expand Up @@ -1236,6 +1245,14 @@ protected FormValidation doTestConnection(@AncestorInPath ItemGroup context, URL
+ pk.getFingerprint() + ")");
}

if (System.getProperty(SSH_PRIVATE_KEY_FILEPATH, "").isEmpty()) {
if (!StringUtils.isEmpty(sshKeysCredentialsId)) {
return FormValidation.ok("Using private key file instead of selected credential");
} else {
return FormValidation.ok("Using private key file");
}
}

return FormValidation.ok(Messages.EC2Cloud_Success());
} catch (AmazonClientException e) {
LOGGER.log(Level.WARNING, "Failed to check EC2 credential", e);
Expand Down
Loading