From 878f19c2a1ce052be26710fae4635b455f830e01 Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Fri, 6 Feb 2015 22:03:03 +0100 Subject: [PATCH] BugFix: Login used root user, even if use preexisting jenkins was enabled --- .../plugins/jclouds/compute/JCloudsSlaveTemplate.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/jclouds-plugin/src/main/java/jenkins/plugins/jclouds/compute/JCloudsSlaveTemplate.java b/jclouds-plugin/src/main/java/jenkins/plugins/jclouds/compute/JCloudsSlaveTemplate.java index 005687e2..0246370c 100644 --- a/jclouds-plugin/src/main/java/jenkins/plugins/jclouds/compute/JCloudsSlaveTemplate.java +++ b/jclouds-plugin/src/main/java/jenkins/plugins/jclouds/compute/JCloudsSlaveTemplate.java @@ -264,13 +264,17 @@ public NodeMetadata get() { options.as(CloudStackTemplateOptions.class).setupStaticNat(assignPublicIp); } + String adminUser = vmUser; + if (this.preExistingJenkinsUser && Strings.isNullOrEmpty(adminUser)) { + adminUser = getJenkinsUser(); + } if (!Strings.isNullOrEmpty(vmPassword)) { - LoginCredentials lc = LoginCredentials.builder().user(vmUser).password(vmPassword).build(); + LoginCredentials lc = LoginCredentials.builder().user(adminUser).password(vmPassword).build(); options.overrideLoginCredentials(lc); - } else if (!Strings.isNullOrEmpty(getCloud().privateKey) && !Strings.isNullOrEmpty(vmUser)) { + } else if (!Strings.isNullOrEmpty(getCloud().privateKey) && !Strings.isNullOrEmpty(adminUser)) { // Skip overriding the credentials if we don't have a VM admin user specified - there are cases where we want the private // key but we don't to use it for the admin user creds. - LoginCredentials lc = LoginCredentials.builder().user(vmUser).privateKey(getCloud().privateKey).build(); + LoginCredentials lc = LoginCredentials.builder().user(adminUser).privateKey(getCloud().privateKey).build(); options.overrideLoginCredentials(lc); }