Skip to content
Permalink
Browse files

Merge pull request #112 from mikefero/windows-images-2.8

[JENKINS-31655] Copying and executing slave.jar on Windows slave
  • Loading branch information
mikefero committed Dec 1, 2015
2 parents 3daf0c2 + d5d46e9 commit 07b49674bea852c0085e05151fa092990b14bbdc
@@ -18,6 +18,8 @@
import com.trilead.ssh2.ServerHostKeyVerifier;
import com.trilead.ssh2.Session;

import shaded.com.google.common.base.Strings;

/**
* The launcher that launches the jenkins slave.jar on the Slave. Uses the SSHKeyPair configured in the cloud profile settings, and logs in to the server via
* SSH, and starts the slave.jar.
@@ -68,9 +70,14 @@ else if (bootstrapResult == SAMEUSER)

SCPClient scp = conn.createSCPClient();
logger.println("Copying slave.jar");
scp.put(Hudson.getInstance().getJnlpJars("slave.jar").readFully(), "slave.jar", "/tmp");

String launchString = "cd /tmp && java " + slave.getJvmOptions() + " -jar slave.jar";
String destinationDirectory = "";
if (!slave.isWindows())
destinationDirectory = "/tmp";
scp.put(Hudson.getInstance().getJnlpJars("slave.jar").readFully(), "slave.jar", destinationDirectory);

String launchString = "java " + slave.getJvmOptions() + " -jar slave.jar";
if (!Strings.isNullOrEmpty(destinationDirectory))
launchString = "cd " + destinationDirectory + " && " + launchString;
logger.println("Launching slave agent: " + launchString);
final Session sess = conn.openSession();
sess.execCommand(launchString);
@@ -37,13 +37,14 @@
private final String privateKey;
private final boolean authSudo;
private final String jvmOptions;
private final boolean isWindows;

@DataBoundConstructor
@SuppressWarnings("rawtypes")
public JCloudsSlave(String cloudName, String name, String nodeDescription, String remoteFS, String numExecutors, Mode mode, String labelString,
ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties, boolean stopOnTerminate,
int overrideRetentionTime, String user, String password, String privateKey, boolean authSudo, String jvmOptions) throws Descriptor.FormException,
IOException {
int overrideRetentionTime, String user, String password, String privateKey, boolean authSudo, String jvmOptions, boolean isWindows)
throws Descriptor.FormException, IOException {
super(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, nodeProperties);
this.stopOnTerminate = stopOnTerminate;
this.cloudName = cloudName;
@@ -53,6 +54,7 @@ public JCloudsSlave(String cloudName, String name, String nodeDescription, Strin
this.privateKey = privateKey;
this.authSudo = authSudo;
this.jvmOptions = jvmOptions;
this.isWindows = isWindows;
}

/**
@@ -74,16 +76,18 @@ public JCloudsSlave(String cloudName, String name, String nodeDescription, Strin
* - if true, suspend the slave rather than terminating it.
* @param overrideRetentionTime
* - Retention time to use specifically for this slave, overriding the cloud default.
* @param isWindows
* - True if slave is Windows; false otherwise
* @throws IOException
* @throws Descriptor.FormException
*/
public JCloudsSlave(final String cloudName, final String fsRoot, NodeMetadata metadata, final String labelString, final String description,
final String numExecutors, final boolean stopOnTerminate, final int overrideRetentionTime, String jvmOptions) throws IOException,
Descriptor.FormException {
final String numExecutors, final boolean stopOnTerminate, final int overrideRetentionTime, String jvmOptions, boolean isWindows)
throws IOException, Descriptor.FormException {
this(cloudName, metadata.getName(), description, fsRoot, numExecutors, Mode.EXCLUSIVE, labelString, new JCloudsLauncher(),
new JCloudsRetentionStrategy(), Collections.<NodeProperty<?>> emptyList(), stopOnTerminate, overrideRetentionTime, metadata.getCredentials()
.getUser(), metadata.getCredentials().getPassword(), metadata.getCredentials().getPrivateKey(), metadata.getCredentials()
.shouldAuthenticateSudo(), jvmOptions);
.shouldAuthenticateSudo(), jvmOptions, isWindows);
this.nodeMetaData = metadata;
this.nodeId = nodeMetaData.getId();
}
@@ -146,6 +150,13 @@ public String getCloudName() {
return cloudName;
}

/**
* Get the flag for determining if the slave is a Windows machine
*/
public boolean isWindows() {
return isWindows;
}

public boolean isPendingDelete() {
return pendingDelete;
}
@@ -96,6 +96,7 @@
public final boolean assignPublicIp;
public final String networks;
public final String securityGroups;
public final boolean isWindows;

private transient Set<LabelAtom> labelSet;

@@ -107,7 +108,7 @@ public JCloudsSlaveTemplate(final String name, final String imageId, final Strin
final String initScript, final String userData, final String numExecutors, final boolean stopOnTerminate, final String vmPassword, final String vmUser,
final boolean preInstalledJava, final String jvmOptions, final String jenkinsUser, final boolean preExistingJenkinsUser, final String fsRoot,
final boolean allowSudo, final boolean installPrivateKey, final int overrideRetentionTime, final int spoolDelayMs, final boolean assignFloatingIp,
final String keyPairName, final boolean assignPublicIp, final String networks, final String securityGroups) {
final String keyPairName, final boolean assignPublicIp, final String networks, final String securityGroups, final boolean isWindows) {

this.name = Util.fixEmptyAndTrim(name);
this.imageId = Util.fixEmptyAndTrim(imageId);
@@ -140,6 +141,7 @@ public JCloudsSlaveTemplate(final String name, final String imageId, final Strin
this.assignPublicIp = assignPublicIp;
this.networks = networks;
this.securityGroups = securityGroups;
this.isWindows = isWindows;
readResolve();
}

@@ -192,7 +194,7 @@ public JCloudsSlave provisionSlave(TaskListener listener) throws IOException {

try {
return new JCloudsSlave(getCloud().getDisplayName(), getFsRoot(), nodeMetadata, labelString, description, numExecutors, stopOnTerminate,
overrideRetentionTime, getJvmOptions());
overrideRetentionTime, getJvmOptions(), isWindows);
} catch (Descriptor.FormException e) {
throw new AssertionError("Invalid configuration " + e.getMessage());
}
@@ -141,6 +141,10 @@
<f:entry title="Security Groups" field="securityGroups">
<f:textbox />
</f:entry>

<f:entry title="${%Is Windows Image}" field="isWindows">
<f:checkbox />
</f:entry>
</f:section>

<f:section title="Open Stack Options">
@@ -157,7 +161,7 @@
<f:checkbox default="true"/>
</f:entry>
</f:section>

</f:advanced>
<f:entry title="">
<div align="right">
@@ -14,7 +14,7 @@ public void testConfigRoundtrip() throws Exception {
String name = "testSlave";
JCloudsSlaveTemplate originalTemplate = new JCloudsSlaveTemplate(name, "imageId", null, "hardwareId", 1, 512, "osFamily", "osVersion", "locationId",
"jclouds-slave-type1 jclouds-type2", "Description", "initScript", null, "1", false, null, null, true, "jenkins", null, false, null, false,
false, 5, 0, true, "jenkins", true, "network1_id,network2_id", "security_group1,security_group2");
false, 5, 0, true, "jenkins", true, "network1_id,network2_id", "security_group1,security_group2", false);

List<JCloudsSlaveTemplate> templates = new ArrayList<JCloudsSlaveTemplate>();
templates.add(originalTemplate);

0 comments on commit 07b4967

Please sign in to comment.
You can’t perform that action at this time.