Package hudson
Class Launcher
java.lang.Object
hudson.Launcher
- Direct Known Subclasses:
Launcher.DecoratedLauncher,Launcher.DummyLauncher,Launcher.LocalLauncher,Launcher.RemoteLauncher
Starts a process.
This hides the difference between running programs locally vs remotely.
'env' parameter
To allow important environment variables to be copied over to the remote machine, the 'env' parameter shouldn't contain default inherited environment variables (which often contains machine-specific information, like PATH, TIMEZONE, etc.)
Launcher is responsible for inheriting environment variables.
- Author:
- Kohsuke Kawaguchi
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA launcher which delegates to a provided inner launcher.static classstatic classstatic classLauncherthat launches process locally.final classBuilder pattern for configuring a process to launch.static classLaunches processes remotely by using the given channel.static interfaceRemoting interface of a remote process -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final hudson.remoting.VirtualChannelprotected EnvVarsFilterRuleWrapperprotected final TaskListenerstatic booleanDebug option to display full current path instead of just the last token. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor for a decorator.protectedLauncher(TaskListener listener, hudson.remoting.VirtualChannel channel) -
Method Summary
Modifier and TypeMethodDescriptionfinal LauncherdecorateByEnv(EnvVars _env) Returns a decoratedLauncherthat automatically adds the specified environment variables.final LauncherdecorateByPrefix(String... prefix) Returns a decoratedLauncherthat puts the given set of arguments as a prefix to any commands that it invokes.final LauncherdecorateFor(Node node) Returns a decoratedLauncherfor the given node.hudson.remoting.VirtualChannelGets the channel that can be used to run a program remotely.Deprecated.since 2008-11-16.Gets theTaskListenerthat this launcher uses to report the commands that it's executing.booleanisUnix()Returns true if thisLauncheris going to launch on Unix.abstract voidCallsProcessTree.killAll(Map)to kill processes.final Launcher.ProcStarterlaunch()Launches a process by using a builder-pattern to configure the parameters.abstract Proclaunch(Launcher.ProcStarter starter) Primarily invoked fromLauncher.ProcStarter.start()to start a process with a specific launcher.final Proclaunch(String[] cmd, boolean[] mask, String[] env, InputStream in, OutputStream out) Deprecated.as of 1.311 Uselaunch()and its associated builder patternlaunch(String[] cmd, boolean[] mask, String[] env, InputStream in, OutputStream out, FilePath workDir) Deprecated.as of 1.311 Uselaunch()and its associated builder patternfinal Proclaunch(String[] cmd, boolean[] mask, String[] env, OutputStream out, FilePath workDir) Deprecated.as of 1.311 Uselaunch()and its associated builder patternfinal Proclaunch(String[] cmd, boolean[] mask, Map<String, String> env, InputStream in, OutputStream out) Deprecated.as of 1.311 Uselaunch()and its associated builder patternfinal ProcDeprecated.as of 1.311 Uselaunch()and its associated builder patternfinal Proclaunch(String[] cmd, String[] env, InputStream in, OutputStream out) Deprecated.as of 1.311 Uselaunch()and its associated builder patternlaunch(String[] cmd, String[] env, InputStream in, OutputStream out, FilePath workDir) Deprecated.as of 1.311 Uselaunch()and its associated builder patternfinal Proclaunch(String[] cmd, String[] env, OutputStream out, FilePath workDir) Deprecated.as of 1.311 Uselaunch()and its associated builder patternfinal Proclaunch(String[] cmd, Map<String, String> env, InputStream in, OutputStream out) Deprecated.as of 1.311 Uselaunch()and its associated builder patternfinal ProcDeprecated.as of 1.311 Uselaunch()and its associated builder patternfinal Proclaunch(String cmd, String[] env, OutputStream out, FilePath workDir) Deprecated.as of 1.311 Uselaunch()and its associated builder patternfinal ProcDeprecated.as of 1.311 Uselaunch()and its associated builder patternabstract hudson.remoting.ChannellaunchChannel(String[] cmd, OutputStream out, FilePath workDir, Map<String, String> envVars) Launches a specified process and connects its input/output to aChannel, then return it.protected final voidmaskedPrintCommandLine(String[] cmd, boolean[] mask, FilePath workDir) protected final voidmaskedPrintCommandLine(List<String> cmd, boolean[] mask, FilePath workDir) Prints out the command line to the listener with some portions masked to prevent sensitive information from being recorded on the listener.voidprepareFilterRules(Run<?, ?> run, EnvVarsFilterableBuilder builder) Build the environment filter rules that will be applied on the environment variablesprotected final voidprintCommandLine(String[] cmd, FilePath workDir) Prints out the command line to the listener so that users know what we are doing.protected voidsetEnvVarsFilterRuleWrapper(EnvVarsFilterRuleWrapper envVarsFilterRuleWrapper)
-
Field Details
-
listener
-
channel
@CheckForNull protected final hudson.remoting.VirtualChannel channel -
envVarsFilterRuleWrapper
@Restricted(org.kohsuke.accmod.restrictions.Beta.class) protected EnvVarsFilterRuleWrapper envVarsFilterRuleWrapper -
showFullPath
public static boolean showFullPathDebug option to display full current path instead of just the last token.
-
-
Constructor Details
-
Launcher
protected Launcher(@NonNull TaskListener listener, @CheckForNull hudson.remoting.VirtualChannel channel) -
Launcher
Constructor for a decorator.- Parameters:
launcher- Launcher to be decorated
-
-
Method Details
-
prepareFilterRules
@Restricted(org.kohsuke.accmod.restrictions.Beta.class) public void prepareFilterRules(@CheckForNull Run<?, ?> run, @NonNull EnvVarsFilterableBuilder builder) Build the environment filter rules that will be applied on the environment variables- Parameters:
run- The run that requested the command interpretation, could benullif outside of a run context.builder- The builder that asked to run this command- Since:
- 2.246
-
setEnvVarsFilterRuleWrapper
@Restricted(org.kohsuke.accmod.restrictions.Beta.class) protected void setEnvVarsFilterRuleWrapper(EnvVarsFilterRuleWrapper envVarsFilterRuleWrapper) -
getChannel
@CheckForNull public hudson.remoting.VirtualChannel getChannel()Gets the channel that can be used to run a program remotely.- Returns:
nullif the target node is not configured to support this. this is a transitional measure. Note that a launcher for the built-in node is always non-null.
-
getListener
Gets theTaskListenerthat this launcher uses to report the commands that it's executing.- Returns:
- Task listener
-
getComputer
Deprecated.since 2008-11-16. See the javadoc for why this is inherently unreliable. If you are trying to figure out the currentComputerfrom within a build, useFilePath.toComputer()orComputer.currentComputer().If thisLauncheris encapsulating an execution on a specificComputer, return it.Because of the way internal Hudson abstractions are set up (that is,
Launcheronly needs aVirtualChannelto do its job and isn't really required that the channel comes from an existingComputer), this method may not always the rightComputerinstance.- Returns:
nullif this launcher is not created from aComputerobject.
-
launch
Launches a process by using a builder-pattern to configure the parameters. -
launch
@Deprecated public final Proc launch(String cmd, Map<String, String> env, OutputStream out, FilePath workDir) throws IOExceptionDeprecated.as of 1.311 Uselaunch()and its associated builder pattern- Throws:
IOException
-
launch
@Deprecated public final Proc launch(String[] cmd, Map<String, String> env, OutputStream out, FilePath workDir) throws IOExceptionDeprecated.as of 1.311 Uselaunch()and its associated builder pattern- Throws:
IOException
-
launch
@Deprecated public final Proc launch(String[] cmd, Map<String, String> env, InputStream in, OutputStream out) throws IOExceptionDeprecated.as of 1.311 Uselaunch()and its associated builder pattern- Throws:
IOException
-
launch
@Deprecated public final Proc launch(String[] cmd, boolean[] mask, Map<String, String> env, OutputStream out, FilePath workDir) throws IOExceptionDeprecated.as of 1.311 Uselaunch()and its associated builder patternLaunch a command with optional censoring of arguments from the listener (Note: The censored portions will remain visible through /proc, pargs, process explorer, etc. i.e. people logged in on the same machine This version of the launch command just ensures that it is not visible from a build log which is exposed via the web)- Parameters:
cmd- The command and all it's arguments.mask- Which of the command and arguments should be masked from the listenerenv- Environment variable overrides.out- stdout and stderr of the process will be sent to this stream. the stream won't be closed.workDir- null if the working directory could be anything.- Returns:
- The process of the command.
- Throws:
IOException- When there are IO problems.
-
launch
@Deprecated public final Proc launch(String[] cmd, boolean[] mask, Map<String, String> env, InputStream in, OutputStream out) throws IOExceptionDeprecated.as of 1.311 Uselaunch()and its associated builder patternLaunch a command with optional censoring of arguments from the listener (Note: The censored portions will remain visible through /proc, pargs, process explorer, etc. i.e. people logged in on the same machine This version of the launch command just ensures that it is not visible from a build log which is exposed via the web)- Parameters:
cmd- The command and all it's arguments.mask- Which of the command and arguments should be masked from the listenerenv- Environment variable overrides.in- null if there's no input.out- stdout and stderr of the process will be sent to this stream. the stream won't be closed.- Returns:
- The process of the command.
- Throws:
IOException- When there are IO problems.
-
launch
@Deprecated public final Proc launch(String cmd, String[] env, OutputStream out, FilePath workDir) throws IOException Deprecated.as of 1.311 Uselaunch()and its associated builder pattern- Throws:
IOException
-
launch
@Deprecated public final Proc launch(String[] cmd, String[] env, OutputStream out, FilePath workDir) throws IOException Deprecated.as of 1.311 Uselaunch()and its associated builder pattern- Throws:
IOException
-
launch
@Deprecated public final Proc launch(String[] cmd, String[] env, InputStream in, OutputStream out) throws IOException Deprecated.as of 1.311 Uselaunch()and its associated builder pattern- Throws:
IOException
-
launch
@Deprecated public final Proc launch(String[] cmd, boolean[] mask, String[] env, OutputStream out, FilePath workDir) throws IOException Deprecated.as of 1.311 Uselaunch()and its associated builder patternLaunch a command with optional censoring of arguments from the listener (Note: The censored portions will remain visible through /proc, pargs, process explorer, etc. i.e. people logged in on the same machine This version of the launch command just ensures that it is not visible from a build log which is exposed via the web)- Parameters:
cmd- The command and all it's arguments.mask- Which of the command and arguments should be masked from the listenerenv- Environment variable overrides.out- stdout and stderr of the process will be sent to this stream. the stream won't be closed.workDir- null if the working directory could be anything.- Returns:
- The process of the command.
- Throws:
IOException- When there are IO problems.
-
launch
@Deprecated public final Proc launch(String[] cmd, boolean[] mask, String[] env, InputStream in, OutputStream out) throws IOException Deprecated.as of 1.311 Uselaunch()and its associated builder patternLaunch a command with optional censoring of arguments from the listener (Note: The censored portions will remain visible through /proc, pargs, process explorer, etc. i.e. people logged in on the same machine This version of the launch command just ensures that it is not visible from a build log which is exposed via the web)- Parameters:
cmd- The command and all it's arguments.mask- Which of the command and arguments should be masked from the listenerenv- Environment variable overrides.in- null if there's no input.out- stdout and stderr of the process will be sent to this stream. the stream won't be closed.- Returns:
- The process of the command.
- Throws:
IOException- When there are IO problems.
-
launch
@Deprecated public Proc launch(String[] cmd, String[] env, InputStream in, OutputStream out, FilePath workDir) throws IOException Deprecated.as of 1.311 Uselaunch()and its associated builder pattern- Parameters:
env- Environment variable overrides.in- null if there's no input.out- stdout and stderr of the process will be sent to this stream. the stream won't be closed.workDir- null if the working directory could be anything.- Throws:
IOException
-
launch
@Deprecated public Proc launch(String[] cmd, boolean[] mask, String[] env, InputStream in, OutputStream out, FilePath workDir) throws IOException Deprecated.as of 1.311 Uselaunch()and its associated builder patternLaunch a command with optional censoring of arguments from the listener (Note: The censored portions will remain visible through /proc, pargs, process explorer, etc. i.e. people logged in on the same machine This version of the launch command just ensures that it is not visible from a build log which is exposed via the web)- Parameters:
cmd- The command and all it's arguments.mask- Which of the command and arguments should be masked from the listenerenv- Environment variable overrides.in- null if there's no input.out- stdout and stderr of the process will be sent to this stream. the stream won't be closed.workDir- null if the working directory could be anything.- Returns:
- The process of the command.
- Throws:
IOException- When there are IO problems.
-
launch
Primarily invoked fromLauncher.ProcStarter.start()to start a process with a specific launcher.- Throws:
IOException
-
launchChannel
public abstract hudson.remoting.Channel launchChannel(@NonNull String[] cmd, @NonNull OutputStream out, @CheckForNull FilePath workDir, @NonNull Map<String, String> envVars) throws IOException, InterruptedExceptionLaunches a specified process and connects its input/output to aChannel, then return it.When the returned channel is terminated, the process will be killed.
- Parameters:
cmd- The commands.out- Where the stderr from the launched process will be sent.workDir- The working directory of the new process, ornullto inherit from the current processenvVars- Environment variable overrides. In addition to what the current process is inherited (if this is going to be launched from an agent, that becomes the "current" process), these variables will be also set.- Throws:
IOExceptionInterruptedException
-
isUnix
public boolean isUnix()Returns true if thisLauncheris going to launch on Unix. -
kill
CallsProcessTree.killAll(Map)to kill processes.- Throws:
IOExceptionInterruptedException
-
printCommandLine
Prints out the command line to the listener so that users know what we are doing. -
maskedPrintCommandLine
protected final void maskedPrintCommandLine(@NonNull List<String> cmd, @CheckForNull boolean[] mask, @CheckForNull FilePath workDir) Prints out the command line to the listener with some portions masked to prevent sensitive information from being recorded on the listener.- Parameters:
cmd- The commandsmask- An array of booleans which control whether a cmd element should be masked (true) or remain unmasked (false).workDir- The work dir.
-
maskedPrintCommandLine
-
decorateFor
Returns a decoratedLauncherfor the given node.- Parameters:
node- Node for which this launcher is created.- Returns:
- Decorated instance of the Launcher.
-
decorateByPrefix
Returns a decoratedLauncherthat puts the given set of arguments as a prefix to any commands that it invokes.- Parameters:
prefix- Prefixes to be appended- Since:
- 1.299
-
decorateByEnv
Returns a decoratedLauncherthat automatically adds the specified environment variables. Those that are specified inLauncher.ProcStarter.envs(String...)will take precedence over what's specified here.- Since:
- 1.489
-