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()); }
int r = launcher.launch().cmds(args).envs(env).stdout(mca).pwd(build.getModuleRoot()).join(); if (0 != r) { return false;
/** * For use with {@link #launch} (or similar) when running commands not inside a build and which therefore might not be easily killed. */ public static int joinWithPossibleTimeout(ProcStarter proc, boolean useTimeout, final TaskListener listener) throws IOException, InterruptedException { return useTimeout ? proc.start().joinWithTimeout(60 * 60, TimeUnit.SECONDS, listener) : proc.join(); }
@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()); }
@Override public void pullImage(TaskListener listener, String image) throws IOException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder() .add("pull") .add(image); Launcher launcher = new Launcher.LocalLauncher(listener); int status = launchDockerCLI(launcher, args) .stdout(launcher.getListener().getLogger()).join(); if (status != 0) { throw new IOException("Failed to pull image " + image); } }
@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()); }
@Override public boolean checkImageExists(TaskListener listener, String image) throws IOException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder() .add("inspect") .add("-f", "'{{.Id}}'") .add(image); ByteArrayOutputStream out = new ByteArrayOutputStream(); Launcher launcher = new Launcher.LocalLauncher(listener); return launchDockerCLI(launcher, args) .stdout(out).stderr(launcher.getListener().getLogger()).join() == 0; }
@Override public void pullImage(TaskListener listener, String image) throws IOException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder() .add("pull") .add(image); Launcher launcher = new Launcher.LocalLauncher(listener); int status = launchDockerCLI(launcher, args) .stdout(launcher.getListener().getLogger()).join(); if (status != 0) { throw new IOException("Failed to pull image " + image); } }
@Override public void removeContainer(TaskListener listener, Container instance) throws IOException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder() .add("rm", "-f", instance.getId()); ByteArrayOutputStream out = new ByteArrayOutputStream(); Launcher launcher = new Launcher.LocalLauncher(listener); int status = launchDockerCLI(launcher, args) .stdout(out).stderr(launcher.getListener().getLogger()).join(); if (status != 0) { throw new IOException("Failed to remove container " + instance.getId()); } }
public void doListViews(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Hudson.getInstance().createLauncher(TaskListener.NULL).launch().cmds(getCleartoolExe(), "lsview", "-short").stdout(baos).join(); rsp.setContentType("text/plain"); rsp.getOutputStream().println("ClearCase Views found:\n"); baos.writeTo(rsp.getOutputStream()); }
@Override public @Nonnull SCMProbeStat stat(@Nonnull String path) throws IOException { try { return SCMProbeStat.fromType(hg.run("locate", "-r", revision.getHash(), "-I", "path:" + path). pwd(cache).join() == 0 ? SCMFile.Type.REGULAR_FILE : SCMFile.Type.NONEXISTENT); } catch (InterruptedException e) { throw new IOException(e); } }
@Test public void testLauncherFactoryIsSane() throws Exception { LauncherFactory factory = TestUtils.createLauncherFactory(j); assertEquals(factory.getStderr(), System.err); OutputStream out = new ByteArrayOutputStream(); factory.launch().stdout(out).cmdAsSingleString("echo hello").join(); assertEquals(out.toString(), "hello\n"); } }
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"))); }
@Override public boolean checkImageExists(TaskListener listener, String image) throws IOException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder() .add("inspect") .add("-f", "'{{.Id}}'") .add(image); ByteArrayOutputStream out = new ByteArrayOutputStream(); Launcher launcher = new Launcher.LocalLauncher(listener); return launchDockerCLI(launcher, args) .stdout(out).stderr(launcher.getListener().getLogger()).join() == 0; }
@Override public void removeContainer(TaskListener listener, Container instance) throws IOException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder() .add("rm", "-f", instance.getId()); ByteArrayOutputStream out = new ByteArrayOutputStream(); Launcher launcher = new Launcher.LocalLauncher(listener); int status = launchDockerCLI(launcher, args) .stdout(out).stderr(launcher.getListener().getLogger()).join(); if (status != 0) { throw new IOException("Failed to remove container " + instance.getId()); } }
@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()); }
/** * 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; } }
@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(); }