Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-39066

hudson.util.ArgumentListBuilder quoting incorrectly in procStarter

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • core
    • None
    • Jenkins 2.19.1, accurev-plugin 0.7.4, MacOS Sierra

      Hi

      I suspect ArgumentListBuilder or ProcStarter for not executing the command correctly.

      I have a login command which accepts no password by "" or ''
      Command execute fine on Windows but not on Unix/MacOS.
      From terminal MacOS executes the command just fine.

      This is how the ProcStarter gets going.
      ProcStarter starter = launcher.launch().cmds(command);

      With the following command:
      The command is: /Applications/AccuRev/bin/accurev login user ""
      Or: "C:\Program Files\AccuRev\bin\accurev.exe" login user ""

      addQuoted("") should give me two quotes.

      Any ideas would be appreciated why Java/Unix is eating my quotes.

      I have tried different escaping but nothing has worked.
      7, 5, 3, 2, 1 back slashes. backticks... single quoting. etc.
      Also tried StringEscapeUtils, even .cmdAsSingleString

      Code in question
      Second Code in question

          private static boolean accurevLogin(//
                                              final AccurevServer server, //
                                              final Map<String, String> accurevEnv, //
                                              final FilePath workspace, //
                                              final TaskListener listener, //
                                              final Launcher launcher) throws IOException, InterruptedException {
              listener.getLogger().println("Authenticating with Accurev server...");
              final ArgumentListBuilder cmd = new ArgumentListBuilder();
              cmd.add("login");
              addServer(cmd, server);
              if (server.isUseNonexpiringLogin()) {
                  cmd.add("-n");
              }
              cmd.add(server.getUsername());
              if (StringUtils.isEmpty(server.getPassword())) {
                  cmd.addQuoted("", true);
              } else {
                  cmd.add(server.getPassword(), true);
              }
              final boolean success = AccurevLauncher.runCommand("login", launcher, cmd, null, accurevEnv, workspace, listener, logger);
              if (success) {
                  listener.getLogger().println("Authentication completed successfully.");
                  return true;
              } else {
                  return false;
              }
          }
      
          private static ProcStarter createProcess(//
                                                   final Launcher launcher, //
                                                   final ArgumentListBuilder machineReadableCommand, //
                                                   final Map<String, String> environmentVariables, //
                                                   final FilePath directoryToRunCommandFrom, //
                                                   final OutputStream stdoutStream, //
                                                   final OutputStream stderrStream) throws IOException, InterruptedException {
              String accurevPath = directoryToRunCommandFrom.act(new FindAccurevClientExe());
              if (!machineReadableCommand.toString().contains(accurevPath)) machineReadableCommand.prepend(accurevPath);
              ProcStarter starter = launcher.launch().cmds(machineReadableCommand);
              Computer c = Computer.currentComputer();
              Node n = c == null ? Jenkins.getInstance() : c.getNode();
              String path = null;
              FilePath filePath = null;
              if (n != null) filePath = n.getRootPath();
              if (filePath != null) path = filePath.getRemote();
              if (StringUtils.isNotBlank(path)) environmentVariables.putIfAbsent("ACCUREV_HOME", path);
              starter = starter.envs(environmentVariables);
              starter = starter.stdout(stdoutStream).stderr(stderrStream);
              starter = starter.pwd(directoryToRunCommandFrom);
              return starter;
          }
      

            Unassigned Unassigned
            casz Joseph Petersen (old)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: