public ProcStarter cmds(String... args) { return cmds(Arrays.asList(args)); }
return new LocalLauncher(out).launch().cmds(jenkinsExe, command).stdout(out).pwd(pwd).join(); } catch (IOException e) { if (e.getMessage().contains("CreateProcess") && e.getMessage().contains("=740")) {
@Override public void restart() throws IOException, InterruptedException { Jenkins jenkins = Jenkins.getInstanceOrNull(); try { if (jenkins != null) { jenkins.cleanUp(); } } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to clean up. Restart will continue.", e); } File me = getHudsonWar(); File home = me.getParentFile(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamTaskListener task = new StreamTaskListener(baos); task.getLogger().println("Restarting a service"); String exe = System.getenv("WINSW_EXECUTABLE"); File executable; if (exe!=null) executable = new File(exe); else executable = new File(home, "hudson.exe"); if (!executable.exists()) executable = new File(home, "jenkins.exe"); // use restart! to run hudson/jenkins.exe restart in a separate process, so it doesn't kill itself int r = new LocalLauncher(task).launch().cmds(executable, "restart!") .stdout(task).pwd(home).join(); if(r!=0) throw new IOException(baos.toString()); }
/** * Fills a {@link ProcStarter} with all the parameters configured by this * builder. */ public ProcStarter launch(Launcher launcher) { return launcher.launch().cmds(toFullArguments()).pwd(pwd); } private static final long serialVersionUID = 1L;
public int runCmd(String[] commands, FilePath workspace, OutputStream logger, Launcher launcher, EnvVars envVars) throws InterruptedException, IOException { try { return launcher.launch().cmds(commands).envs(envVars).stdout(logger).stderr(logger).pwd(workspace).start().join(); } catch (IOException ex) { logger.write(ex.getMessage().getBytes()); if (printDebugOutput) { logger.write(Throwables.getStackTraceAsString(ex).getBytes()); } return 1; } }
@Override public void restart() throws IOException, InterruptedException { File me = getHudsonWar(); File home = me.getParentFile(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamTaskListener task = new StreamTaskListener(baos); task.getLogger().println("Restarting a service"); int r = new LocalLauncher(task).launch().cmds(new File(home, "hudson.exe"), "restart") .stdout(task).pwd(home).join(); if(r!=0) throw new IOException(baos.toString()); }
/** * Fills a {@link ProcStarter} with all the parameters configured by this builder. */ public ProcStarter launch(Launcher launcher) { return launcher.launch().cmds(toFullArguments()).pwd(pwd); }
/** * Copies a {@link ProcStarter}. */ @Nonnull public ProcStarter copy() { ProcStarter rhs = new ProcStarter().cmds(commands).pwd(pwd).masks(masks).stdin(stdin).stdout(stdout).stderr(stderr).envs(envs).quiet(quiet); rhs.reverseStdin = this.reverseStdin; rhs.reverseStderr = this.reverseStderr; rhs.reverseStdout = this.reverseStdout; return rhs; } }
protected void assumeDocker() throws Exception { Launcher.LocalLauncher localLauncher = new Launcher.LocalLauncher(StreamTaskListener.NULL); try { Assume.assumeThat("Docker working", localLauncher.launch().cmds(DockerTool.getExecutable(null, null, null, null), "ps").join(), is(0)); } catch (IOException x) { Assume.assumeNoException("have Docker installed", x); } DockerClient dockerClient = new DockerClient(localLauncher, null, null); Assume.assumeFalse("Docker version not < 1.3", dockerClient.version().isOlderThan(new VersionNumber("1.3"))); }
int r = launcher.launch().cmds(args).envs(env).stdout(mca).pwd(build.getModuleRoot()).join(); if (0 != r) { return false;
envVars.put(e.getKey(),e.getValue()); r = join(launcher.launch().cmds(buildCommandLine(script)).envs(envVars).stdout(listener).pwd(ws).start());
public RemoteProcess call() throws IOException { final Channel channel = getOpenChannelOrFail(); Launcher.ProcStarter ps = new LocalLauncher(listener).launch(); ps.cmds(cmd).masks(masks).envs(env).stdin(in).stderr(err).quiet(quiet); if (stdoutListener != null) { ps.stdout(stdoutListener.getLogger());
/** * Checks if "java" is in PATH on the given node. * * <p> * If it's not, then the user must specify a configured JDK, * so this is often useful for form field validation. */ public static boolean isDefaultJDKValid(Node n) { try { TaskListener listener = new StreamTaskListener(new NullStream()); Launcher launcher = n.createLauncher(listener); return launcher.launch().cmds("java","-fullversion").stdout(listener).join()==0; } catch (IOException e) { return false; } catch (InterruptedException e) { return false; } }
/** * @param env * Environment variable overrides. * @param in * null if there's no input. * @param workDir * null if the working directory could be anything. * @param out * stdout and stderr of the process will be sent to this stream. * the stream won't be closed. * * @deprecated as of 1.311 * Use {@link #launch()} and its associated builder pattern */ @Deprecated public Proc launch(String[] cmd, String[] env, InputStream in, OutputStream out, FilePath workDir) throws IOException { return launch(launch().cmds(cmd).envs(env).stdin(in).stdout(out).pwd(workDir)); }
@Override public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { FilePath dir = preferredLocation(tool, node); // TODO support Unix scripts with interpreter line (see Shell.buildCommandLine) FilePath script = dir.createTextTempFile("hudson", getCommandFileExtension(), command); try { String cmd[] = getCommandCall(script); int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join(); if (r != 0) { throw new IOException("Command returned status " + r); } } finally { script.delete(); } return dir.child(getToolHome()); }
private static int system(File pwd, TaskListener listener, String... args) throws IOException, InterruptedException { return new LocalLauncher(listener).launch().cmds(args).stdout(System.out).pwd(pwd).join(); }
/** * Primarily invoked from {@link ProcStarter#start()} to start a process with a specific launcher. */ public abstract Proc launch(@Nonnull ProcStarter starter) throws IOException;
/** * Copies a {@link ProcStarter}. */ @Nonnull public ProcStarter copy() { ProcStarter rhs = new ProcStarter().cmds(commands).pwd(pwd).masks(masks).stdin(stdin).stdout(stdout).stderr(stderr).envs(envs).quiet(quiet); rhs.stdoutListener = stdoutListener; rhs.reverseStdin = this.reverseStdin; rhs.reverseStderr = this.reverseStderr; rhs.reverseStdout = this.reverseStdout; return rhs; } }
/** * Passes a white-space separated single-string command (like "cat abc def") and parse them * as a command argument. This method also handles quotes. */ public ProcStarter cmdAsSingleString(String s) { return cmds(QuotedStringTokenizer.tokenize(s)); }
/** * Fills a {@link ProcStarter} with all the parameters configured by this builder. */ public ProcStarter launch(Launcher launcher) { return launcher.launch().cmds(toFullArguments()).pwd(pwd); }