Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
I tried to get this working but no cigar, unfortunately I've run out of
time.
  • Loading branch information
Geordie Rogers committed Sep 19, 2022
1 parent ea11667 commit 294c8ee
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@
import hudson.slaves.CommandLauncher;
import hudson.slaves.ComputerLauncher;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -234,11 +230,9 @@ protected void launchScript(EC2Computer computer, TaskListener listener) throws
sess.close();
}

// TODO: parse the version number. maven-enforcer-plugin might help
final String javaPath = node.javaPath;
executeRemote(computer, conn, javaPath + " -fullversion",
"sudo amazon-linux-extras install java-openjdk11; "
+ "sudo yum install -y fontconfig java-11-openjdk", logger, listener);
checkJavaInstalled(computer, conn, javaPath, logger, listener);
java
executeRemote(computer, conn, "which scp", "sudo yum install -y openssh-clients", logger, listener);

// Always copy so we get the most recent remoting.jar
Expand Down Expand Up @@ -311,6 +305,24 @@ private boolean executeRemote(EC2Computer computer, Connection conn, String chec
return true;
}

private boolean checkJavaInstalled(EC2Computer computer, Connection conn, String javaPath, PrintStream logger, TaskListener listener)
throws IOException, InterruptedException {
String installCommand = "sudo amazon-linux-extras install java-openjdk11; "
+ "sudo yum install -y fontconfig java-11-openjdk";

logInfo(computer, listener,"Verifying: " + javaPath);
if (conn.exec(javaPath + "-fullversion", logger) == 0 ) {
// If supported java version
return true;
}
logInfo(computer, listener, "Installing: java");
if (conn.exec(installCommand, logger) == 0) {
return true;
}
logWarning(computer, listener, "Failed to install: " + installCommand);
return false;
}

private File createIdentityKeyFile(EC2Computer computer) throws IOException {
EC2PrivateKey ec2PrivateKey = computer.getCloud().resolvePrivateKey();
String privateKey = "";
Expand Down

0 comments on commit 294c8ee

Please sign in to comment.