public abstract class Launcher extends Object
This hides the difference between running programs locally vs remotely.
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.
FilePath.createLauncher(TaskListener)
Modifier and Type | Class and Description |
---|---|
static class |
Launcher.DecoratedLauncher
A launcher which delegates to a provided inner launcher.
|
static class |
Launcher.DummyLauncher |
static class |
Launcher.IOTriplet |
static class |
Launcher.LocalLauncher
Launcher that launches process locally. |
class |
Launcher.ProcStarter
Builder pattern for configuring a process to launch.
|
static class |
Launcher.RemoteLauncher
Launches processes remotely by using the given channel.
|
static interface |
Launcher.RemoteProcess
Remoting interface of a remote process
|
Modifier and Type | Field and Description |
---|---|
protected hudson.remoting.VirtualChannel |
channel |
protected TaskListener |
listener |
static boolean |
showFullPath
Debug option to display full current path instead of just the last token.
|
Modifier | Constructor and Description |
---|---|
protected |
Launcher(Launcher launcher)
Constructor for a decorator.
|
|
Launcher(TaskListener listener,
hudson.remoting.VirtualChannel channel) |
Modifier and Type | Method and Description |
---|---|
Launcher |
decorateByEnv(EnvVars _env)
Returns a decorated
Launcher that automatically adds the specified environment
variables. |
Launcher |
decorateByPrefix(String... prefix)
Returns a decorated
Launcher that puts the given set of arguments as a prefix to any commands
that it invokes. |
Launcher |
decorateFor(Node node)
Returns a decorated
Launcher for the given node. |
hudson.remoting.VirtualChannel |
getChannel()
Gets the channel that can be used to run a program remotely.
|
Computer |
getComputer()
Deprecated.
since 2008-11-16.
See the javadoc for why this is inherently unreliable. If you are trying to
figure out the current
Computer from within a build, use
Computer.currentComputer() |
TaskListener |
getListener()
Gets the
TaskListener that this launcher uses to
report the commands that it's executing. |
boolean |
isUnix()
Returns true if this
Launcher is going to launch on Unix. |
abstract void |
kill(Map<String,String> modelEnvVars)
Calls
ProcessTree.killAll(Map) to kill processes. |
Launcher.ProcStarter |
launch()
Launches a process by using a builder-pattern to configure
the parameters.
|
abstract Proc |
launch(Launcher.ProcStarter starter)
Primarily invoked from
Launcher.ProcStarter.start() to start a process with a specific launcher. |
Proc |
launch(String[] cmd,
boolean[] mask,
Map<String,String> env,
InputStream in,
OutputStream out)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
Proc |
launch(String[] cmd,
boolean[] mask,
Map<String,String> env,
OutputStream out,
FilePath workDir)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
Proc |
launch(String[] cmd,
boolean[] mask,
String[] env,
InputStream in,
OutputStream out)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
Proc |
launch(String[] cmd,
boolean[] mask,
String[] env,
InputStream in,
OutputStream out,
FilePath workDir)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
Proc |
launch(String[] cmd,
boolean[] mask,
String[] env,
OutputStream out,
FilePath workDir)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
Proc |
launch(String[] cmd,
Map<String,String> env,
InputStream in,
OutputStream out)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
Proc |
launch(String[] cmd,
Map<String,String> env,
OutputStream out,
FilePath workDir)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
Proc |
launch(String[] cmd,
String[] env,
InputStream in,
OutputStream out)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
Proc |
launch(String[] cmd,
String[] env,
InputStream in,
OutputStream out,
FilePath workDir)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
Proc |
launch(String[] cmd,
String[] env,
OutputStream out,
FilePath workDir)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
Proc |
launch(String cmd,
Map<String,String> env,
OutputStream out,
FilePath workDir)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
Proc |
launch(String cmd,
String[] env,
OutputStream out,
FilePath workDir)
Deprecated.
as of 1.311
Use
launch() and its associated builder pattern |
abstract hudson.remoting.Channel |
launchChannel(String[] cmd,
OutputStream out,
FilePath workDir,
Map<String,String> envVars)
Launches a specified process and connects its input/output to a
Channel , then
return it. |
protected void |
maskedPrintCommandLine(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.
|
protected void |
maskedPrintCommandLine(String[] cmd,
boolean[] mask,
FilePath workDir) |
protected void |
printCommandLine(String[] cmd,
FilePath workDir)
Prints out the command line to the listener so that users know what we are doing.
|
protected final TaskListener listener
protected final hudson.remoting.VirtualChannel channel
public static boolean showFullPath
public Launcher(TaskListener listener, hudson.remoting.VirtualChannel channel)
protected Launcher(Launcher launcher)
public hudson.remoting.VirtualChannel getChannel()
public TaskListener getListener()
TaskListener
that this launcher uses to
report the commands that it's executing.@Deprecated public Computer getComputer()
Computer
from within a build, use
Computer.currentComputer()
Launcher
is encapsulating an execution on a specific Computer
,
return it.
Because of the way internal Hudson abstractions are set up (that is, Launcher
only
needs a VirtualChannel
to do its job and isn't really required that the channel
comes from an existing Computer
), this method may not always the right Computer
instance.
Computer
object.public final Launcher.ProcStarter launch()
@Deprecated public final Proc launch(String cmd, Map<String,String> env, OutputStream out, FilePath workDir) throws IOException
launch()
and its associated builder patternIOException
@Deprecated public final Proc launch(String[] cmd, Map<String,String> env, OutputStream out, FilePath workDir) throws IOException
launch()
and its associated builder patternIOException
@Deprecated public final Proc launch(String[] cmd, Map<String,String> env, InputStream in, OutputStream out) throws IOException
launch()
and its associated builder patternIOException
@Deprecated public final Proc launch(String[] cmd, boolean[] mask, Map<String,String> env, OutputStream out, FilePath workDir) throws IOException
launch()
and its associated builder patterncmd
- 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.IOException
- When there are IO problems.@Deprecated public final Proc launch(String[] cmd, boolean[] mask, Map<String,String> env, InputStream in, OutputStream out) throws IOException
launch()
and its associated builder patterncmd
- 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.IOException
- When there are IO problems.@Deprecated public final Proc launch(String cmd, String[] env, OutputStream out, FilePath workDir) throws IOException
launch()
and its associated builder patternIOException
@Deprecated public final Proc launch(String[] cmd, String[] env, OutputStream out, FilePath workDir) throws IOException
launch()
and its associated builder patternIOException
@Deprecated public final Proc launch(String[] cmd, String[] env, InputStream in, OutputStream out) throws IOException
launch()
and its associated builder patternIOException
@Deprecated public final Proc launch(String[] cmd, boolean[] mask, String[] env, OutputStream out, FilePath workDir) throws IOException
launch()
and its associated builder patterncmd
- 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.IOException
- When there are IO problems.@Deprecated public final Proc launch(String[] cmd, boolean[] mask, String[] env, InputStream in, OutputStream out) throws IOException
launch()
and its associated builder patterncmd
- 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.IOException
- When there are IO problems.@Deprecated public Proc launch(String[] cmd, String[] env, InputStream in, OutputStream out, FilePath workDir) throws IOException
launch()
and its associated builder patternenv
- Environment variable overrides.in
- null if there's no input.workDir
- null if the working directory could be anything.out
- stdout and stderr of the process will be sent to this stream.
the stream won't be closed.IOException
@Deprecated public Proc launch(String[] cmd, boolean[] mask, String[] env, InputStream in, OutputStream out, FilePath workDir) throws IOException
launch()
and its associated builder patterncmd
- 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.IOException
- When there are IO problems.public abstract Proc launch(Launcher.ProcStarter starter) throws IOException
Launcher.ProcStarter.start()
to start a process with a specific launcher.IOException
public abstract hudson.remoting.Channel launchChannel(String[] cmd, OutputStream out, FilePath workDir, Map<String,String> envVars) throws IOException, InterruptedException
Channel
, then
return it.
When the returned channel is terminated, the process will be killed.
out
- Where the stderr from the launched process will be sent.workDir
- The working directory of the new process, or null to 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 a slave agent, that
becomes the "current" process), these variables will be also set.IOException
InterruptedException
public boolean isUnix()
Launcher
is going to launch on Unix.public abstract void kill(Map<String,String> modelEnvVars) throws IOException, InterruptedException
ProcessTree.killAll(Map)
to kill processes.IOException
InterruptedException
protected final void printCommandLine(String[] cmd, FilePath workDir)
protected final void maskedPrintCommandLine(List<String> cmd, boolean[] mask, FilePath workDir)
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.protected final void maskedPrintCommandLine(String[] cmd, boolean[] mask, FilePath workDir)
public final Launcher decorateFor(Node node)
Launcher
for the given node.public final Launcher decorateByPrefix(String... prefix)
Launcher
that puts the given set of arguments as a prefix to any commands
that it invokes.public final Launcher decorateByEnv(EnvVars _env)
Launcher
that automatically adds the specified environment
variables.
Those that are specified in Launcher.ProcStarter.envs(String...)
will take precedence over
what's specified here.Copyright © 2019. All rights reserved.