private LaunchResult launch(@CheckForNull @Nonnull EnvVars launchEnv, boolean quiet, FilePath pwd, @Nonnull ArgumentListBuilder args) throws IOException, InterruptedException { // Prepend the docker command args.prepend(DockerTool.getExecutable(toolName, node, launcher.getListener(), launchEnv)); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Executing docker command {0}", args.toString()); } Launcher.ProcStarter procStarter = launcher.launch(); if (pwd != null) { procStarter.pwd(pwd); } LaunchResult result = new LaunchResult(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); result.setStatus(procStarter.quiet(quiet).cmds(args).envs(launchEnv).stdout(out).stderr(err).start().joinWithTimeout(CLIENT_TIMEOUT, TimeUnit.SECONDS, launcher.getListener())); final String charsetName = Charset.defaultCharset().name(); result.setOut(out.toString(charsetName)); result.setErr(err.toString(charsetName)); return result; }
@Test public void credentialsSSHKeyTest() throws Exception { BasicSSHUserPrivateKey.PrivateKeySource source = new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource( "test key"); BasicSSHUserPrivateKey credentials = new BasicSSHUserPrivateKey( CredentialsScope.GLOBAL, "", "testuser", source, null, null); HgExe hgexe = new HgExe( this.mercurialInstallation, credentials, this.launcher, j.jenkins, this.listener, this.vars); ArgumentListBuilder b = hgexe.seed(false); Matcher matcher = Pattern.compile("ssh\\s-i\\s(.+)\\s-l\\stestuser").matcher(b.toCommandArray()[2]); matcher.find(); String fileName = matcher.group(1); assertEquals("test key", FileUtils.readFileToString(new File(fileName))); assertEquals(new ArgumentListBuilder( "hg", "--config", "******").toString(), b.toString()); hgexe.close(); }
.add("--interactive", "--attach", remotingContainer.getId()); prependArgs(args); new CommandLauncher(args.toString(), dockerHost.getEnvironment()).launch(computer, listener); return remotingContainer;
.add("--interactive", "--attach", remotingContainer.getId()); prependArgs(args); new CommandLauncher(args.toString(), dockerHost.getEnvironment()).launch(computer, listener); return remotingContainer;
@Test public void credentialsUsernamePasswordTest() throws Exception { UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl( CredentialsScope.GLOBAL, "", "", "testuser", "testpassword"); HgExe hgexe = new HgExe( this.mercurialInstallation, credentials, this.launcher, j.jenkins, this.listener, this.vars); ArgumentListBuilder b = hgexe.seed(false); assertEquals(new ArgumentListBuilder( "hg", "--config", "auth.jenkins.prefix=*", "--config", "auth.jenkins.username=testuser", "--config", "auth.jenkins.password=testpassword", "--config", "auth.jenkins.schemes=http https") .toList(), b.toList()); assertEquals(new ArgumentListBuilder( "hg", "--config", "auth.jenkins.prefix=*", "--config", "******", "--config", "******", "--config", "auth.jenkins.schemes=http https").toString(), b.toString()); hgexe.close(); }
@Bug(5723) @Test public void customConfiguration() throws Exception { HgExe hgexe = new HgExe(new MercurialInstallation(INSTALLATION, "", "hg", false, false, false, "[defaults]\nclone = --uncompressed\n", null), null, this.launcher, j.jenkins, this.listener, this.vars); ArgumentListBuilder b = hgexe.seed(false).add("clone", "http://some.thing/"); assertEquals("hg --config defaults.clone=--uncompressed clone http://some.thing/", b.toString()); }