private boolean checkConfigs(XTriggerLog xTriggerLog) {
    if (project == null || project.isEmpty()) {
      xTriggerLog.info("Ontrack: No project configured");
      return true;
    }

    if (branch == null || branch.isEmpty()) {
      xTriggerLog.info("Ontrack: No branch configured");
      return true;
    }
    return false;
  }
  @Override
  protected boolean checkIfModified(Node node, XTriggerLog xTriggerLog) throws XTriggerException {
    if (checkConfigs(xTriggerLog)) return false;

    FilePath lastBuildNrFile =
        new FilePath(node.getRootPath(), String.format("%s-lastbuild-lastBuildNr", job.getName()));
    String lastBuildNr = loadLastBuildNr(xTriggerLog, lastBuildNrFile);

    // Gets the last build
    BuildSummary lastBuild = getBuildSummary();

    // Found
    if (lastBuild != null) {
      String name = lastBuild.getName();
      xTriggerLog.info(
          String.format(
              "Found build '%s' for branch '%s' and project '%s'%n", name, branch, project));
      try {
        if (lastBuildNr == null || lastBuildNr.isEmpty() || !lastBuildNr.equals(name)) {
          saveLastBuildNr(name, xTriggerLog, lastBuildNrFile);
          return true;
        }
      } catch (IOException e) {
        logException(xTriggerLog, e);
      } catch (InterruptedException e) {
        logException(xTriggerLog, e);
      }
    }

    return false;
  }
  @Override
  protected boolean checkIfModified(Node executingNode, XTriggerLog log)
      throws ScriptTriggerException {

    int expectedExitCode = getExpectedExitCode();
    log.info("The expected script execution code is " + expectedExitCode);

    return checkIfModifiedWithScriptsEvaluation(executingNode, expectedExitCode, log);
  }
Пример #4
0
  private String getPackageVersion(String wsRoot, String id) throws IOException {
    String line;

    if (packages.containsKey(id)) {
      return packages.get(id);
    }

    String nuget =
        new File(nugetExe).isAbsolute() ? nugetExe : new File(wsRoot, nugetExe).getAbsolutePath();

    String cmd = String.format("\"%s\" list %s -NonInteractive", nuget, id);
    for (int retried = 0; retried < retryCount; retried++) {
      log.info(String.format("Running: %s", cmd));
      Process p = Runtime.getRuntime().exec(cmd);
      BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));
      BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
      while ((line = stdout.readLine()) != null) {
        log.info(line);
        String[] parts = line.split(" ", 2);
        if (parts.length == 2 && parts[0].equalsIgnoreCase(id)) {
          packages.put(id, parts[1]);
          return parts[1];
        }
      }
      stdout.close();
      while ((line = stderr.readLine()) != null) {
        log.error(line);
      }
      stderr.close();
      try {
        p.waitFor();
        break;
      } catch (InterruptedException ex) {
        log.error(ex.toString());
        log.info(String.format("Retrying: %i", retried));
      }
    }
    return null;
  }
  private static String loadLastBuildNr(XTriggerLog xTriggerLog, FilePath lastBuildNrFile) {
    String lastBuildNr = null;

    try {
      if (lastBuildNrFile.exists()) {
        lastBuildNr = lastBuildNrFile.readToString();

        xTriggerLog.info(String.format("Loaded buildNr: %s", lastBuildNr));
      }
    } catch (IOException e) {
      logException(xTriggerLog, e);
    } catch (InterruptedException e) {
      logException(xTriggerLog, e);
    }

    return lastBuildNr;
  }
 private boolean testExpectedExitCode(int exitCode, int expectedExitCode, XTriggerLog log) {
   log.info(String.format("The exit code is '%s'.", exitCode));
   log.info(String.format("Testing if the script execution code returns '%s'.", expectedExitCode));
   return expectedExitCode == exitCode;
 }
 private static void saveLastBuildNr(
     String lastBuildNr, XTriggerLog xTriggerLog, FilePath lastBuildNrFile)
     throws IOException, InterruptedException {
   lastBuildNrFile.write(lastBuildNr, "UTF-8");
   xTriggerLog.info(String.format("Wrote buildNr: %s", lastBuildNr));
 }