@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()); }
/** * Gets the executable path of this maven on the given target system. */ public String getExecutable(Launcher launcher) throws IOException, InterruptedException { return launcher.getChannel().call(new GetExecutable()); } private class GetExecutable extends MasterToSlaveCallable<String, IOException> {
@Override public boolean isUnix() { return outer.isUnix(); }
@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 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(); } };
private String getMavenVersionFromConsole() throws Exception { ArgumentListBuilder args = new ArgumentListBuilder(); args.add(getExecutable()); args.add("--version"); env.put(M2_HOME, getHome().getRemote()); env.put(MAVEN_SKIP_RC, TRUE); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); Proc process = launcher.launch() .cmds(args) .envs(env) .pwd(build.getWorkspace()) .stdout(buffer) .start(); String output = new String(buffer.toByteArray()); if (muxlog.isTraceEnabled()) { muxlog.trace("Process output:\n{}", output);
public boolean pullImage(String image) throws IOException, InterruptedException { ArgumentListBuilder args = dockerCommand() .add("pull", image); OutputStream out = verbose ? listener.getLogger() : new ByteArrayOutputStream(); OutputStream err = verbose ? listener.getLogger() : new ByteArrayOutputStream(); int status = launcher.launch() .envs(getEnvVars()) .cmds(args) .stdout(out).stderr(err).join(); return status == 0; }
public String buildImage(FilePath workspace, String dockerfile, boolean forcePull, boolean noCache) throws IOException, InterruptedException { .add("build"); args.add("--pull"); args.add("--no-cache"); args.add("--file", dockerfile) .add(workspace.getRemote()); args.add("--label", "jenkins-project=" + this.build.getProject().getName()); args.add("--label", "jenkins-build-number=" + this.build.getNumber()); OutputStream logOutputStream = listener.getLogger(); OutputStream err = listener.getLogger(); ByteArrayOutputStream resultOutputStream = new ByteArrayOutputStream(); TeeOutputStream teeOutputStream = new TeeOutputStream(logOutputStream, resultOutputStream); int status = launcher.launch() .envs(getEnvVars()) .cmds(args) .stdout(teeOutputStream).stderr(err).join(); if (status != 0) { throw new RuntimeException("Failed to build docker image from project Dockerfile"); Matcher matcher = pattern.matcher(resultOutputStream.toString("UTF-8")); if (!matcher.find())
.replaceAll("[\t\r\n]+"," "); ArgumentListBuilder args = new ArgumentListBuilder(); MavenInstallation mi = getMaven(); if(mi==null) { String execName = build.getWorkspace().act(new DecideDefaultMavenCommand(normalizedTarget)); args.add(execName); } else { mi = mi.forNode(Computer.currentComputer().getNode(), listener); return false; args.add(exec); args.add("-Dmaven.repo.local=" + build.getWorkspace().child(".repository")); args.addTokenized(normalizedTarget); wrapUpArguments(args,normalizedTarget,build,launcher,listener); if (!launcher.isUnix()) { args = args.toWindowsCommand(); int r = launcher.launch().cmds(args).envs(env).stdout(mca).pwd(build.getModuleRoot()).join(); if (0 != r) { return false;
private void addCommand(String cmd, String home){ String command = cmd; if (!StringUtils.isEmpty(home)){ command = new FilePath(launcher.getChannel(), home).child("bin").child(command).getRemote(); } commandLine.add(command); }
public static void exeConan(ArgumentListBuilder args, FilePath pwd, Launcher launcher, TaskListener listener, Run build, EnvVars env) { boolean failed; try { if (!pwd.exists()) { pwd.mkdirs(); if (launcher.isUnix()) { boolean hasMaskedArguments = args.hasMaskedArguments(); StringBuilder sb = new StringBuilder(); for (String arg : args.toList()) { sb.append(escapeUnixArgument(arg)).append(" "); args.clear(); args.add("sh", "-c"); if (hasMaskedArguments) { args = args.toWindowsCommand(); int exitValue = launcher.launch().cmds(args).envs(env).stdout(listener).pwd(pwd).join(); failed = (exitValue != 0); } catch (Exception e) { listener.error("Couldn't execute the conan client executable. " + e.getMessage()); build.setResult(Result.FAILURE); throw new Run.RunnerAbortedException();
private void runCommentsRemoverProcess(FilePath workspace, Launcher launcher, TaskListener listener, File removerScriptDir, File outputDirPath) throws IOException, InterruptedException { String pythonPath = getDescriptor().getPythonPath(); String pipPath = getDescriptor().getPipPath(); String pipExecutable = StringUtils.isEmpty(pythonPath) ? "pip" : pipPath; String[] pipCommand = new String[]{pipExecutable, "install", "-r", removerScriptDir + File.separator + "requirements.txt", "-q"}; listener.getLogger().println("Installing pip requirements [" + StringUtils.join(pipCommand, " ") + "]..."); runProcess(launcher.launch().cmds(pipCommand).readStdout().start(), listener); String pythonExecutable = StringUtils.isEmpty(pythonPath) ? "python" : pythonPath; String[] commentsRemoverCommand = new String[]{pythonExecutable, removerScriptDir + File.separator + COMMENTS_REMOVER_ENTRY_FILE, workspace.getRemote() + File.separator + filename, language, outputDirPath.getAbsolutePath()}; listener.getLogger().println("Executing script [" + StringUtils.join(commentsRemoverCommand, " ") + "]..."); runProcess(launcher.launch().cmds(commentsRemoverCommand).readStdout().start(), listener); }
@Override protected Boolean run() throws Exception { pomFile = new FilePath(ws, step.getPomFile()).getRemote(); failOnSnapshot = step.isFailOnSnapshot(); dryRun = step.isDryRun(); this.version = step.getVersion(); this.versionPerModule = step.getVersionPerModule(); Boolean call = launcher.getChannel().call(new MasterToSlaveCallable<Boolean, IOException>() { public Boolean call() throws IOException { return transformPoms(); } }); return call; }
@Override protected BuildInfo run() throws Exception { BuildInfo buildInfo = Utils.prepareBuildinfo(build, step.getBuildInfo()); FilePath conanHomeDirectory = new FilePath(launcher.getChannel(), step.getConanHome()); persistBuildProperties(buildInfo, conanHomeDirectory); EnvVars extendedEnv = new EnvVars(env); extendedEnv.put(Utils.CONAN_USER_HOME, step.getConanHome()); execConanCommand(extendedEnv); FilePath logFilePath = execConanCollectBuildInfo(extendedEnv); Build regularBuildInfo = Utils.getGeneratedBuildInfo(build, listener, launcher, logFilePath.getRemote()); buildInfo.append(regularBuildInfo); return buildInfo; }
@Override public KeyMaterial materialize() throws IOException, InterruptedException { FilePath dockerConfig = createSecretsDirectory(); try { // TODO on Docker 17.07+ use --password-stdin EnvVars envWithConfig = new EnvVars(env); envWithConfig.put("DOCKER_CONFIG", dockerConfig.getRemote()); if (launcher.launch().cmds(new ArgumentListBuilder(dockerExecutable, "login", "-u", username, "-p").add(password, true).add(endpoint)).envs(envWithConfig).stdout(listener).join() != 0) { throw new AbortException("docker login failed"); } } catch (IOException | InterruptedException x) { try { dockerConfig.deleteRecursive(); } catch (Exception x2) { x.addSuppressed(x2); } throw x; } return new RegistryKeyMaterial(dockerConfig, new EnvVars("DOCKER_CONFIG", dockerConfig.getRemote())); }
@Override protected String getMavenAgentClassPath(MavenInstallation mvn, FilePath slaveRoot, BuildListener listener) throws IOException, InterruptedException { String classWorldsJar = getLauncher().getChannel().call(new GetClassWorldsJar(mvn.getHome(),listener)); String path = classPathEntry(slaveRoot, Maven33Main.class, "maven33-agent", listener) + (getLauncher().isUnix()?":":";")+classWorldsJar; // TODO this configurable?? path += (getLauncher().isUnix()?":":";")+mvn.getHomeDir().getPath()+"/conf/logging"; return path; }
throws InterruptedException, IOException { ArgumentListBuilder args = new ArgumentListBuilder("ln", "-s", target.getRemote(), link.getRemote()); return 0 == launcher.launch().cmds(args).stdout(listener).join(); } catch (IOException e) { e.printStackTrace(listener.fatalError(Messages.CommandInterpreter_CommandFailed()));
/** * Starts the new process as configured. */ public Proc start() throws IOException { return launch(this); }
public boolean perform() throws Exception { FilePath rootFileObject = new FilePath(this.workspace, config.getRootObject()); final DeployerContext deployerContext = new DeployerContext(config, rootFileObject, listener); final VirtualChannel channel = launcher.getChannel(); if (null == channel) throw new IllegalStateException("Null Channel (?)"); final Future<Boolean> booleanFuture = channel.callAsync(new SlaveDeployerCallable(deployerContext)); return booleanFuture.get(); } }
public FilePath getHome() { if (home == null) { home = new FilePath(launcher.getChannel(), installation.getHome()); } return home; }