Package hudson.plugins.sshslaves
Class SSHLauncher
- java.lang.Object
-
- hudson.model.AbstractDescribableImpl<ComputerLauncher>
-
- hudson.slaves.ComputerLauncher
-
- hudson.plugins.sshslaves.SSHLauncher
-
- All Implemented Interfaces:
ExtensionPoint
,Describable<ComputerLauncher>
public class SSHLauncher extends ComputerLauncher
A computer launcher that tries to start a linux agent by opening an SSH connection and trying to find java.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SSHLauncher.DescriptorImpl
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Field Summary
Fields Modifier and Type Field Description static String
AGENT_JAR
static Integer
DEFAULT_LAUNCH_TIMEOUT_SECONDS
static Integer
DEFAULT_MAX_NUM_RETRIES
static Integer
DEFAULT_RETRY_WAIT_TIME
static int
DEFAULT_SSH_PORT
static String
JAR_CACHE_DIR
static String
JAR_CACHE_PARAM
String
javaPath
Field javaPath.Integer
launchTimeoutSeconds
Field launchTimeoutSeconds.Integer
maxNumRetries
Field maxNumRetries.String
prefixStartSlaveCmd
Field prefixStartSlaveCmd.Integer
retryWaitTime
Field retryWaitTime (seconds).static String
SLASH_AGENT_JAR
static com.cloudbees.plugins.credentials.domains.SchemeRequirement
SSH_SCHEME
The scheme requirement.String
suffixStartSlaveCmd
Field suffixStartSlaveCmd.static String
WORK_DIR_PARAM
-
Fields inherited from class hudson.slaves.ComputerLauncher
LIST
-
-
Constructor Summary
Constructors Constructor Description SSHLauncher(String host, int port, String credentialsId)
Constructor SSHLauncher creates a new SSHLauncher instance.SSHLauncher(String host, int port, String credentialsId, String jvmOptions, String javaPath, String prefixStartSlaveCmd, String suffixStartSlaveCmd, Integer launchTimeoutSeconds, Integer maxNumRetries, Integer retryWaitTime, SshHostKeyVerificationStrategy sshHostKeyVerificationStrategy)
Constructor SSHLauncher creates a new SSHLauncher instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
afterDisconnect(SlaveComputer slaveComputer, TaskListener listener)
com.trilead.ssh2.Connection
getConnection()
com.cloudbees.plugins.credentials.common.StandardUsernameCredentials
getCredentials()
String
getCredentialsId()
String
getHost()
Getter for property 'host'.String
getJavaPath()
Deprecated.String
getJvmOptions()
Gets the optional JVM Options used to launch the agent JVM.Integer
getLaunchTimeoutSeconds()
Getter for property 'launchTimeoutSeconds'Integer
getMaxNumRetries()
Getter for property 'maxNumRetries'int
getPort()
Getter for property 'port'.String
getPrefixStartSlaveCmd()
Integer
getRetryWaitTime()
Getter for property 'retryWaitTime'SshHostKeyVerificationStrategy
getSshHostKeyVerificationStrategy()
String
getSuffixStartSlaveCmd()
boolean
getTcpNoDelay()
static String
getTimestamp()
Gets the formatted current time stamp.boolean
getTrackCredentials()
Enable/Disable the credential tracking, this tracking store information about where it is used a credential, in this case in a node.String
getWorkDir()
String
getWorkDirParam(String workingDirectory)
static String
getWorkingDirectory(SlaveComputer computer)
Returns the remote root workspace (without trailing slash).boolean
isLaunchSupported()
void
launch(SlaveComputer computer, TaskListener listener)
String
logConfiguration()
static com.cloudbees.plugins.credentials.common.StandardUsernameCredentials
lookupSystemCredentials(String credentialsId)
protected void
openConnection(TaskListener listener, SlaveComputer computer)
Object
readResolve()
protected void
reportEnvironment(TaskListener listener)
void
setHost(String value)
void
setJavaPath(String value)
void
setJvmOptions(String value)
void
setLaunchTimeoutSeconds(Integer value)
void
setMaxNumRetries(Integer value)
void
setPort(int value)
void
setPrefixStartSlaveCmd(String value)
void
setRetryWaitTime(Integer value)
void
setSshHostKeyVerificationStrategy(SshHostKeyVerificationStrategy value)
void
setSuffixStartSlaveCmd(String value)
void
setTcpNoDelay(boolean tcpNoDelay)
void
setWorkDir(String workDir)
-
Methods inherited from class hudson.slaves.ComputerLauncher
afterDisconnect, beforeDisconnect, beforeDisconnect, checkJavaVersion, launch
-
Methods inherited from class hudson.model.AbstractDescribableImpl
getDescriptor
-
-
-
-
Field Detail
-
SSH_SCHEME
public static final com.cloudbees.plugins.credentials.domains.SchemeRequirement SSH_SCHEME
The scheme requirement.
-
DEFAULT_MAX_NUM_RETRIES
public static final Integer DEFAULT_MAX_NUM_RETRIES
-
DEFAULT_RETRY_WAIT_TIME
public static final Integer DEFAULT_RETRY_WAIT_TIME
-
DEFAULT_LAUNCH_TIMEOUT_SECONDS
public static final Integer DEFAULT_LAUNCH_TIMEOUT_SECONDS
-
AGENT_JAR
public static final String AGENT_JAR
- See Also:
- Constant Field Values
-
SLASH_AGENT_JAR
public static final String SLASH_AGENT_JAR
- See Also:
- Constant Field Values
-
WORK_DIR_PARAM
public static final String WORK_DIR_PARAM
- See Also:
- Constant Field Values
-
JAR_CACHE_PARAM
public static final String JAR_CACHE_PARAM
- See Also:
- Constant Field Values
-
JAR_CACHE_DIR
public static final String JAR_CACHE_DIR
- See Also:
- Constant Field Values
-
DEFAULT_SSH_PORT
public static final int DEFAULT_SSH_PORT
- See Also:
- Constant Field Values
-
javaPath
public String javaPath
Field javaPath.
-
prefixStartSlaveCmd
public String prefixStartSlaveCmd
Field prefixStartSlaveCmd.
-
suffixStartSlaveCmd
public String suffixStartSlaveCmd
Field suffixStartSlaveCmd.
-
launchTimeoutSeconds
public Integer launchTimeoutSeconds
Field launchTimeoutSeconds.
-
maxNumRetries
public Integer maxNumRetries
Field maxNumRetries.
-
retryWaitTime
public Integer retryWaitTime
Field retryWaitTime (seconds).
-
-
Constructor Detail
-
SSHLauncher
public SSHLauncher(@NonNull String host, int port, String credentialsId, String jvmOptions, String javaPath, String prefixStartSlaveCmd, String suffixStartSlaveCmd, Integer launchTimeoutSeconds, Integer maxNumRetries, Integer retryWaitTime, @CheckForNull SshHostKeyVerificationStrategy sshHostKeyVerificationStrategy)
Constructor SSHLauncher creates a new SSHLauncher instance.- Parameters:
host
- The host to connect to.port
- The port to connect on.credentialsId
- The credentials id to connect as.jvmOptions
- Options passed to the java vm.javaPath
- Path to the host jdk installation. Ifnull
the jdk will be auto detected.prefixStartSlaveCmd
- This will prefix the start agent command. For instance if you want to execute the command with a different shell.suffixStartSlaveCmd
- This will suffix the start agent command.launchTimeoutSeconds
- Launch timeout in secondsmaxNumRetries
- The number of times to retry connection if the SSH connection is refused during initial connectretryWaitTime
- The number of seconds to wait between retriessshHostKeyVerificationStrategy
- Host key verification method selected.
-
-
Method Detail
-
lookupSystemCredentials
public static com.cloudbees.plugins.credentials.common.StandardUsernameCredentials lookupSystemCredentials(String credentialsId)
-
readResolve
public Object readResolve()
-
getCredentials
public com.cloudbees.plugins.credentials.common.StandardUsernameCredentials getCredentials()
-
isLaunchSupported
public boolean isLaunchSupported()
- Overrides:
isLaunchSupported
in classComputerLauncher
-
getJvmOptions
public String getJvmOptions()
Gets the optional JVM Options used to launch the agent JVM.- Returns:
- The optional JVM Options used to launch the agent JVM.
-
getJavaPath
@Deprecated public String getJavaPath()
Deprecated.Gets the optional java command to use to launch the agent JVM.- Returns:
- The optional java command to use to launch the agent JVM.
-
getTimestamp
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static String getTimestamp()
Gets the formatted current time stamp.- Returns:
- the formatted current time stamp.
-
getWorkingDirectory
@CheckForNull public static String getWorkingDirectory(SlaveComputer computer)
Returns the remote root workspace (without trailing slash).- Parameters:
computer
- The computer to get the root workspace of.- Returns:
- the remote root workspace (without trailing slash).
-
launch
public void launch(SlaveComputer computer, TaskListener listener) throws InterruptedException
- Overrides:
launch
in classComputerLauncher
- Throws:
InterruptedException
-
reportEnvironment
protected void reportEnvironment(TaskListener listener) throws IOException, InterruptedException
- Throws:
IOException
InterruptedException
-
openConnection
protected void openConnection(TaskListener listener, SlaveComputer computer) throws IOException, InterruptedException
- Throws:
IOException
InterruptedException
-
afterDisconnect
public void afterDisconnect(SlaveComputer slaveComputer, TaskListener listener)
- Overrides:
afterDisconnect
in classComputerLauncher
-
getCredentialsId
public String getCredentialsId()
-
getSshHostKeyVerificationStrategy
@CheckForNull public SshHostKeyVerificationStrategy getSshHostKeyVerificationStrategy()
-
setSshHostKeyVerificationStrategy
@DataBoundSetter public void setSshHostKeyVerificationStrategy(@CheckForNull SshHostKeyVerificationStrategy value)
-
setJvmOptions
@DataBoundSetter public void setJvmOptions(String value)
-
setJavaPath
@DataBoundSetter public void setJavaPath(String value)
-
setPrefixStartSlaveCmd
@DataBoundSetter public void setPrefixStartSlaveCmd(String value)
-
setSuffixStartSlaveCmd
@DataBoundSetter public void setSuffixStartSlaveCmd(String value)
-
setMaxNumRetries
@DataBoundSetter public void setMaxNumRetries(Integer value)
-
setLaunchTimeoutSeconds
@DataBoundSetter public void setLaunchTimeoutSeconds(Integer value)
-
setRetryWaitTime
@DataBoundSetter public void setRetryWaitTime(Integer value)
-
setPort
public void setPort(int value)
-
setHost
public void setHost(String value)
-
getHost
public String getHost()
Getter for property 'host'.- Returns:
- Value for property 'host'.
-
getPort
public int getPort()
Getter for property 'port'.- Returns:
- Value for property 'port'.
-
getConnection
public com.trilead.ssh2.Connection getConnection()
-
getPrefixStartSlaveCmd
@NonNull public String getPrefixStartSlaveCmd()
-
getSuffixStartSlaveCmd
@NonNull public String getSuffixStartSlaveCmd()
-
getLaunchTimeoutSeconds
@NonNull public Integer getLaunchTimeoutSeconds()
Getter for property 'launchTimeoutSeconds'- Returns:
- launchTimeoutSeconds
-
getMaxNumRetries
@NonNull public Integer getMaxNumRetries()
Getter for property 'maxNumRetries'- Returns:
- maxNumRetries
-
getRetryWaitTime
@NonNull public Integer getRetryWaitTime()
Getter for property 'retryWaitTime'- Returns:
- retryWaitTime
-
getTcpNoDelay
public boolean getTcpNoDelay()
-
setTcpNoDelay
@DataBoundSetter public void setTcpNoDelay(boolean tcpNoDelay)
-
getTrackCredentials
public boolean getTrackCredentials()
Enable/Disable the credential tracking, this tracking store information about where it is used a credential, in this case in a node. If the tracking is enabled and you launch a big number of Agents per day, activate credentials tacking could cause a performance issue see- See Also:
- JENKINS-49235
-
getWorkDir
public String getWorkDir()
-
setWorkDir
@DataBoundSetter public void setWorkDir(String workDir)
-
getWorkDirParam
@NonNull @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public String getWorkDirParam(@NonNull String workingDirectory)
- Parameters:
workingDirectory
- The Working directory set on the configuration of the node.- Returns:
- the remoting parameter to set the workDir, by default it is the same as the working directory configured on the node so "-workDir " + workingDirectory, if workDir is set, he method will return "-workDir " + getWorkDir() if the parameter is set in suffixStartSlaveCmd, the method will return an empty String.
-
logConfiguration
public String logConfiguration()
-
-