use of com.thoughtworks.go.util.ProcessWrapper in project gocd by gocd.
the class CommandLine method run.
public int run(ProcessOutputStreamConsumer outputStreamConsumer, String processTag, String... input) {
if (LOG.isDebugEnabled()) {
LOG.debug("Running " + this);
}
addInput(input);
SafeOutputStreamConsumer safeStreamConsumer = new SafeOutputStreamConsumer(outputStreamConsumer);
safeStreamConsumer.addArguments(arguments);
safeStreamConsumer.addSecrets(secrets);
ProcessWrapper process = execute(safeStreamConsumer, new EnvironmentVariableContext(), processTag);
return process.waitForExit();
}
use of com.thoughtworks.go.util.ProcessWrapper in project gocd by gocd.
the class CommandLine method runOrBomb.
public ConsoleResult runOrBomb(boolean failOnNonZeroReturn, String processTag, String... input) {
addInput(input);
InMemoryStreamConsumer output = ProcessOutputStreamConsumer.inMemoryConsumer();
ProcessWrapper process = execute(output, new EnvironmentVariableContext(), processTag);
int returnValue = process.waitForExit();
ConsoleResult result = new ConsoleResult(returnValue, output.getStdLines(), output.getErrLines(), arguments, secrets, failOnNonZeroReturn);
if (result.failed()) {
throw new CommandLineException(this, result);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Output: \n" + StringUtils.join(result.outputForDisplay(), "\n"));
}
return result;
}
use of com.thoughtworks.go.util.ProcessWrapper in project gocd by gocd.
the class CommandLine method runScript.
public void runScript(Script script, StreamConsumer buildOutputConsumer, EnvironmentVariableContext environmentVariableContext, String processTag) throws CheckedCommandLineException {
LOG.info("Running command: {}", toStringForDisplay());
CompositeConsumer errorStreamConsumer = new CompositeConsumer(CompositeConsumer.ERR, StreamLogger.getWarnLogger(LOG), buildOutputConsumer);
CompositeConsumer outputStreamConsumer = new CompositeConsumer(CompositeConsumer.OUT, StreamLogger.getInfoLogger(LOG), buildOutputConsumer);
// TODO: The build output buffer doesn't take into account Cruise running in multi-threaded mode.
ProcessWrapper process;
int exitCode = -1;
SafeOutputStreamConsumer streamConsumer = null;
try {
streamConsumer = new SafeOutputStreamConsumer(new ProcessOutputStreamConsumer(outputStreamConsumer, errorStreamConsumer));
streamConsumer.addArguments(getArguments());
for (EnvironmentVariableContext.EnvironmentVariable secureEnvironmentVariable : environmentVariableContext.getSecureEnvironmentVariables()) {
streamConsumer.addSecret(new PasswordArgument(secureEnvironmentVariable.value()));
}
process = startProcess(environmentVariableContext, streamConsumer, processTag);
} catch (CommandLineException e) {
String message = String.format("Error happened while attempting to execute '%s'. \nPlease make sure [%s] can be executed on this agent.\n", toStringForDisplay(), getExecutable());
String path = System.getenv("PATH");
streamConsumer.errOutput(message);
streamConsumer.errOutput(String.format("[Debug Information] Environment variable PATH: %s", path));
LOG.error("[Command Line] {}. Path: {}", message, path);
throw new CheckedCommandLineException(message, e);
} catch (IOException e) {
String msg = String.format("Encountered an IO exception while attempting to execute '%s'. Go cannot continue.\n", toStringForDisplay());
streamConsumer.errOutput(msg);
throw new CheckedCommandLineException(msg, e);
}
exitCode = process.waitForExit();
script.setExitCode(exitCode);
}
use of com.thoughtworks.go.util.ProcessWrapper in project gocd by gocd.
the class CommandLine method run.
public int run(ConsoleOutputStreamConsumer outputStreamConsumer, String processTag, String... input) {
LOG.debug("Running {}", this);
addInput(input);
SafeOutputStreamConsumer safeStreamConsumer = new SafeOutputStreamConsumer(outputStreamConsumer);
safeStreamConsumer.addArguments(arguments);
safeStreamConsumer.addSecrets(secrets);
ProcessWrapper process = execute(safeStreamConsumer, new EnvironmentVariableContext(), processTag);
return process.waitForExit();
}
use of com.thoughtworks.go.util.ProcessWrapper in project gocd by gocd.
the class CommandLine method runScript.
public void runScript(Script script, StreamConsumer buildOutputConsumer, EnvironmentVariableContext environmentVariableContext, ProcessTag processTag) throws CheckedCommandLineException {
LOG.info("Running command: {}", toStringForDisplay());
CompositeConsumer errorStreamConsumer = new CompositeConsumer(CompositeConsumer.ERR, StreamLogger.getWarnLogger(LOG), buildOutputConsumer);
CompositeConsumer outputStreamConsumer = new CompositeConsumer(CompositeConsumer.OUT, StreamLogger.getInfoLogger(LOG), buildOutputConsumer);
// TODO: The build output buffer doesn't take into account Cruise running in multi-threaded mode.
ProcessWrapper process;
int exitCode = -1;
SafeOutputStreamConsumer streamConsumer = null;
try {
streamConsumer = new SafeOutputStreamConsumer(new ProcessOutputStreamConsumer(outputStreamConsumer, errorStreamConsumer));
streamConsumer.addArguments(getArguments());
streamConsumer.addSecrets(environmentVariableContext.secrets());
process = startProcess(environmentVariableContext, streamConsumer, processTag);
} catch (CommandLineException e) {
String message = String.format("Error happened while attempting to execute '%s'. \nPlease make sure [%s] can be executed on this agent.\n", toStringForDisplay(), getExecutable());
String path = System.getenv("PATH");
streamConsumer.errOutput(message);
streamConsumer.errOutput(String.format("[Debug Information] Environment variable PATH: %s", path));
LOG.error("[Command Line] {}. Path: {}", message, path);
throw new CheckedCommandLineException(message, e);
} catch (IOException e) {
String msg = String.format("Encountered an IO exception while attempting to execute '%s'. Go cannot continue.\n", toStringForDisplay());
streamConsumer.errOutput(msg);
throw new CheckedCommandLineException(msg, e);
}
exitCode = process.waitForExit();
script.setExitCode(exitCode);
}
Aggregations