Package hudson
Class Launcher.ProcStarter
- java.lang.Object
-
- hudson.Launcher.ProcStarter
-
-
Field Summary
Fields Modifier and Type Field Description protected List<String>commandsprotected String[]envsprotected EnvVarsFilterableBuilderenvVarsFilterableBuilderRepresent the build step, either from legacy build process or from pipeline oneprotected boolean[]masksprotected FilePathpwdprotected booleanreverseStderrTrue to reverse the I/O direction.protected booleanreverseStdinTrue to reverse the I/O direction.protected booleanreverseStdoutTrue to reverse the I/O direction.protected OutputStreamstderrprotected InputStreamstdinprotected OutputStreamstdout
-
Constructor Summary
Constructors Constructor Description ProcStarter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EnvVarsFilterableBuilderbuildStep()Launcher.ProcStarterbuildStep(EnvVarsFilterableBuilder envVarsFilterableBuilder)Specify the build step that want to run the command to enable the environment filtersLauncher.ProcStartercmdAsSingleString(String s)Passes a white-space separated single-string command (like "cat abc def") and parse them as a command argument.List<String>cmds()Launcher.ProcStartercmds(ArgumentListBuilder args)Launcher.ProcStartercmds(File program, String... args)Launcher.ProcStartercmds(String... args)Launcher.ProcStartercmds(List<String> args)Launcher.ProcStartercopy()Copies aLauncher.ProcStarter.String[]envs()Gets a list of environment variables to be set.Launcher.ProcStarterenvs(String... overrides)Launcher.ProcStarterenvs(Map<String,String> overrides)Sets the environment variable overrides.intjoin()Starts the process and waits for its completion.boolean[]masks()Launcher.ProcStartermasks(boolean... masks)Hide parts of the command line from being printed to the log.FilePathpwd()Launcher.ProcStarterpwd(FilePath workDir)Sets the current directory.Launcher.ProcStarterpwd(File workDir)Launcher.ProcStarterpwd(String workDir)booleanquiet()Launcher.ProcStarterquiet(boolean quiet)AllowsLauncher.maskedPrintCommandLine(List, boolean[], FilePath)to be suppressed fromLauncher.LocalLauncher.launch(hudson.Launcher.ProcStarter).Launcher.ProcStarterreadStderr()In addition to the effect ofreadStdout(), indicate that the caller will pumpstderrfrom the child process separately fromstdout.Launcher.ProcStarterreadStdout()Indicates that the caller will pumpstdoutfrom the child process viaProc.getStdout()(whereas by default you callstdout(OutputStream)and let Jenkins pump stdout into yourOutputStreamof choosing.Procstart()Starts the new process as configured.OutputStreamstderr()Gets current STDERR destination.Launcher.ProcStarterstderr(OutputStream err)Controls where the stderr of the process goes.InputStreamstdin()Gets current STDIN destination.Launcher.ProcStarterstdin(InputStream in)Controls where the stdin of the process comes from.OutputStreamstdout()Gets current STDOUT destination.Launcher.ProcStarterstdout(TaskListener out)Sends the stdout to the givenTaskListener.Launcher.ProcStarterstdout(OutputStream out)Sets STDOUT destination.Launcher.ProcStarterwriteStdin()Indicates that the caller will directly write to the child processstdin()viaProc.getStdin().
-
-
-
Field Detail
-
masks
@CheckForNull protected boolean[] masks
-
pwd
@CheckForNull protected FilePath pwd
-
stdout
@CheckForNull protected OutputStream stdout
-
stderr
@CheckForNull protected OutputStream stderr
-
stdin
@CheckForNull protected InputStream stdin
-
envs
@CheckForNull protected String[] envs
-
envVarsFilterableBuilder
@CheckForNull @Restricted(org.kohsuke.accmod.restrictions.Beta.class) protected EnvVarsFilterableBuilder envVarsFilterableBuilder
Represent the build step, either from legacy build process or from pipeline one
-
reverseStdin
protected boolean reverseStdin
True to reverse the I/O direction. For example, ifreverseStdout==true, then we exposeInputStreamfromProcand expect the client to read from it, whereas normally we takeOutputStreamviastdout(OutputStream)and feed stdout into that output.- Since:
- 1.399
-
reverseStdout
protected boolean reverseStdout
True to reverse the I/O direction. For example, ifreverseStdout==true, then we exposeInputStreamfromProcand expect the client to read from it, whereas normally we takeOutputStreamviastdout(OutputStream)and feed stdout into that output.- Since:
- 1.399
-
reverseStderr
protected boolean reverseStderr
True to reverse the I/O direction. For example, ifreverseStdout==true, then we exposeInputStreamfromProcand expect the client to read from it, whereas normally we takeOutputStreamviastdout(OutputStream)and feed stdout into that output.- Since:
- 1.399
-
-
Method Detail
-
cmdAsSingleString
public Launcher.ProcStarter cmdAsSingleString(String s)
Passes a white-space separated single-string command (like "cat abc def") and parse them as a command argument. This method also handles quotes.
-
cmds
public Launcher.ProcStarter cmds(String... args)
-
cmds
public Launcher.ProcStarter cmds(File program, String... args)
-
cmds
public Launcher.ProcStarter cmds(List<String> args)
-
cmds
public Launcher.ProcStarter cmds(ArgumentListBuilder args)
-
masks
public Launcher.ProcStarter masks(@CheckForNull boolean... masks)
Hide parts of the command line from being printed to the log.- Parameters:
masks- true for each position incmds(String[])which should be masked, false to print- Returns:
- this
- See Also:
ArgumentListBuilder.add(String, boolean),Launcher.maskedPrintCommandLine(List, boolean[], FilePath)
-
masks
@CheckForNull public boolean[] masks()
-
quiet
public Launcher.ProcStarter quiet(boolean quiet)
AllowsLauncher.maskedPrintCommandLine(List, boolean[], FilePath)to be suppressed fromLauncher.LocalLauncher.launch(hudson.Launcher.ProcStarter). Useful when the actual command being printed is noisy and unreadable and the caller would rather print diagnostic information in a customized way.- Parameters:
quiet- to suppress printing the command line when starting the process; false to keep default behavior of printing- Returns:
this- Since:
- 1.576
-
quiet
public boolean quiet()
- Since:
- 1.576
-
pwd
public Launcher.ProcStarter pwd(@CheckForNull FilePath workDir)
Sets the current directory.- Parameters:
workDir- Work directory to be used. Ifnull, the default/current directory will be used by the process starter- Returns:
this
-
pwd
public Launcher.ProcStarter pwd(@NonNull File workDir)
-
pwd
public Launcher.ProcStarter pwd(@NonNull String workDir)
-
pwd
@CheckForNull public FilePath pwd()
-
stdout
public Launcher.ProcStarter stdout(@CheckForNull OutputStream out)
Sets STDOUT destination.- Parameters:
out- Output stream. Usenullto send STDOUT to/dev/null.- Returns:
this
-
stdout
public Launcher.ProcStarter stdout(@NonNull TaskListener out)
Sends the stdout to the givenTaskListener.- Parameters:
out- Task listener (must be safely remotable)- Returns:
this
-
stdout
@CheckForNull public OutputStream stdout()
Gets current STDOUT destination.- Returns:
- STDOUT output stream.
nullif STDOUT is suppressed or undefined.
-
stderr
public Launcher.ProcStarter stderr(@CheckForNull OutputStream err)
Controls where the stderr of the process goes. By default, it's bundled into stdout.
-
stderr
@CheckForNull public OutputStream stderr()
Gets current STDERR destination.- Returns:
- STDERR output stream.
nullif suppressed or undefined.
-
stdin
@NonNull public Launcher.ProcStarter stdin(@CheckForNull InputStream in)
Controls where the stdin of the process comes from. By default,/dev/null.- Returns:
this
-
stdin
@CheckForNull public InputStream stdin()
Gets current STDIN destination.- Returns:
- STDIN output stream.
nullif suppressed or undefined.
-
envs
public Launcher.ProcStarter envs(@NonNull Map<String,String> overrides)
Sets the environment variable overrides.In addition to what the current process is inherited (if this is going to be launched from a agent agent, that becomes the "current" process), these variables will be also set.
- Parameters:
overrides- Environment variables to be overridden- Returns:
this
-
envs
public Launcher.ProcStarter envs(@CheckForNull String... overrides)
- Parameters:
overrides- List of "VAR=VALUE". Seeenvs(Map)for the semantics.- Returns:
this
-
envs
@NonNull public String[] envs()
Gets a list of environment variables to be set. Returns an empty array if envs field has not been initialized.- Returns:
- If initialized, returns a copy of internal envs array. Otherwise - a new empty array.
-
readStdout
public Launcher.ProcStarter readStdout()
Indicates that the caller will pumpstdoutfrom the child process viaProc.getStdout()(whereas by default you callstdout(OutputStream)and let Jenkins pump stdout into yourOutputStreamof choosing.When this method is called,
Proc.getStdout()will read the combined output ofstdout/stderrfrom the child process, unlessreadStderr()is called separately, which lets the caller read those two streams separately.- Returns:
this- Since:
- 1.399
-
readStderr
public Launcher.ProcStarter readStderr()
In addition to the effect ofreadStdout(), indicate that the caller will pumpstderrfrom the child process separately fromstdout. The stderr will be readable fromProc.getStderr()whileProc.getStdout()reads from stdout.- Returns:
this- Since:
- 1.399
-
writeStdin
public Launcher.ProcStarter writeStdin()
Indicates that the caller will directly write to the child processstdin()viaProc.getStdin(). (Whereas by default you callstdin(InputStream)and let Jenkins pump yourInputStreamof choosing to stdin.)- Returns:
this- Since:
- 1.399
-
buildStep
@Restricted(org.kohsuke.accmod.restrictions.Beta.class) public Launcher.ProcStarter buildStep(EnvVarsFilterableBuilder envVarsFilterableBuilder)
Specify the build step that want to run the command to enable the environment filters- Returns:
this- Since:
- 2.246
-
buildStep
@Restricted(org.kohsuke.accmod.restrictions.Beta.class) @CheckForNull public EnvVarsFilterableBuilder buildStep()
- Returns:
- if set, returns the build step that wants to run the command
- Since:
- 2.246
-
start
public Proc start() throws IOException
Starts the new process as configured.- Throws:
IOException
-
join
public int join() throws IOException, InterruptedExceptionStarts the process and waits for its completion.- Returns:
- Return code of the invoked process
- Throws:
IOException- Operation error (e.g. remote call failure)InterruptedException- The process has been interrupted
-
copy
@NonNull public Launcher.ProcStarter copy()
Copies aLauncher.ProcStarter.
-
-