@Override public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { Charset charset = Charset.defaultCharset(); FilePath basePath = new FilePath(f); Launcher launcher = basePath.createLauncher(new StreamTaskListener(new NullOutputStream(), charset)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Proc starter = launcher.launch().cmdAsSingleString("uname -m").stdout(baos).start(); int exitCode = starter.join(); if (exitCode != 0) { throw new IOException("Fail to execute 'uname -m' because: " + baos.toString(charset.name())); } return new String(baos.toByteArray(), charset).trim(); } };
public String runCommandForOutput(String command) throws DebianizingException { try { String actualCommand = MessageFormat.format("bash -c ''{0}''", command); return CharStreams.toString(new InputStreamReader(launcher.launch().cmdAsSingleString(actualCommand).readStdout().start().getStdout())); } catch (IOException e) { e.printStackTrace(listener.getLogger()); throw new DebianizingException(MessageFormat.format("Command <{0}> failed", command), e); } }
.cmdAsSingleString("kubectl config --kubeconfig=\"" + configFile.getRemote() + "\" set-cluster k8s --server=" + serverUrl + tlsConfig) .join(); .cmdAsSingleString("kubectl config --kubeconfig=\"" + configFile.getRemote() + "\" set-credentials cluster-admin " + login) .masks(false, false, false, false, false, false, true) .join(); .cmdAsSingleString("kubectl config --kubeconfig=\"" + configFile.getRemote() + "\" set-context k8s --cluster=k8s --user=cluster-admin") .join(); if (status != 0) throw new IOException("Failed to run kubectl config "+status); .cmdAsSingleString("kubectl config --kubeconfig=\"" + configFile.getRemote() + "\" use-context k8s") .join(); if (status != 0) throw new IOException("Failed to run kubectl config "+status);
.stdout(stdout) .stderr(stderr) .cmdAsSingleString(cmd) .start().join() == 0;
@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"); } }