/** * Method copies the agent jar to the remote system. * * @param listener The listener. * @param workingDirectory The directory into which the agent jar will be copied. * * @throws IOException If something goes wrong. */ @edu.umd.cs.findbugs.annotations.SuppressFBWarnings( value="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", justification="there is a bug related with Java 11 bytecode see https://github.com/spotbugs/spotbugs/issues/756") private void copyAgentJar(TaskListener listener, String workingDirectory) throws IOException, InterruptedException { String fileName = workingDirectory + SLASH_AGENT_JAR;
listener.getLogger().println(Messages.SSHLauncher_CopyingAgentJar(getTimestamp())); byte[] agentJar = new Slave.JnlpJar(AGENT_JAR).readFully();
// If the agent jar already exists see if it needs to be updated boolean overwrite = true; if (sftpClient.exists(fileName)) { String sourceAgentHash = getMd5Hash(agentJar); String existingAgentHash = getMd5Hash(readInputStreamIntoByteArrayAndClose(sftpClient.read(fileName))); listener.getLogger().println(MessageFormat.format( "Source agent hash is {0}. " + "Installed agent hash is {1}", sourceAgentHash, existingAgentHash));
if (overwrite) { try { // try to delete the file incase the agent we are copying is shorter than the agent // that is already there sftpClient.rm(fileName); } catch (IOException e) { // the file did not exist... so no need to delete it! }
try (OutputStream os = sftpClient.writeToFile(fileName)) { os.write(agentJar); listener.getLogger() .println(Messages.SSHLauncher_CopiedXXXBytes(getTimestamp(), agentJar.length)); } catch (Error error) { throw error; } catch (Throwable e) { throw new IOException(Messages.SSHLauncher_ErrorCopyingAgentJarTo(fileName), e); } }else{ listener.getLogger().println("Verified agent jar. No update is necessary."); } } catch (Error error) { throw error; } catch (Throwable e) { throw new IOException(Messages.SSHLauncher_ErrorCopyingAgentJarInto(workingDirectory), e); } } catch (IOException e) { if (sftpClient == null) { e.printStackTrace(listener.error(Messages.SSHLauncher_StartingSCPClient(getTimestamp()))); // lets try to recover if the agent doesn't have an SFTP service copySlaveJarUsingSCP(listener, workingDirectory); } else { throw e; } } finally { if (sftpClient != null) { sftpClient.close(); } } }
try { computer.setChannel(session.getStdout(), session.getStdin(), listener.getLogger(), null); } catch (InterruptedException e) { session.close(); thrownewIOException(Messages.SSHLauncher_AbortedDuringConnectionOpen(), e); } catch (IOException e) { try { // often times error this early means the JVM has died, so let's see if we can capture all stderr // and exit code thrownewAbortException(getSessionOutcomeMessage(session, false)); } catch (InterruptedException x) { thrownewIOException(e); } } }
Remote_root_directory and Remoting_Work_directory分析