Java Code Examples for hudson.model.Run#getPreviousBuild()

The following examples show how to use hudson.model.Run#getPreviousBuild() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuildListener.java    From hubot-steps-plugin with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressFBWarnings
public void onCompleted(Run<?, ?> run, TaskListener listener) {
  HubotSite site = HubotSite.get(run.getParent(), listener);
  if (run.getPreviousBuild() != null) {
    Type type = Type.fromResults(run.getPreviousBuild().getResult(), run.getResult());
    if (site != null && site.getNotifications() != null) {
      for (Config config : site.getNotifications()) {
        if (config.isNotifyEnabled()) {
          if (config.getNotificationType().equals(type)) {
            if (Util.fixEmpty(config.getRoomNames()) != null) {
              for (String roomName : config.getRoomNames().split(",")) {
                sendMessage(run, listener, type, site, roomName.trim(), config);
              }
            } else {
              sendMessage(run, listener, type, site, null, config);
            }
          }
        }
      }
    }
  }
  super.onCompleted(run, listener);
}
 
Example 2
Source File: AnchoreProjectAction.java    From anchore-container-scanner-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * @return the most current AnchoreAction of the associated job
 */
public AnchoreAction getLastAnchoreAction() {
  final Run<?,?> tb = this.job.getLastSuccessfulBuild();

  Run<?,?> b = this.job.getLastBuild();
  while (b != null) {
    AnchoreAction a = b.getAction(AnchoreAction.class);
    if (a != null && (!b.isBuilding())) {
      return a;
    }
    if (b == tb) {
      // no Anchore result available
      return null;
    }
    b = b.getPreviousBuild();
  }
  return null;
}
 
Example 3
Source File: AnchoreAction.java    From anchore-container-scanner-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the Anchore result of the previous build, if it's recorded, or null.
 * @return the previous AnchoreAction
 */
public AnchoreAction getPreviousResult() {
  Run<?,?> b = this.build;
  while(true) {
    b = b.getPreviousBuild();
    if (b == null) {
      return null;
    }
    AnchoreAction r = b.getAction(AnchoreAction.class);
    if (r != null) {
      if (r == this) {
        throw new IllegalStateException(this + " was attached to both " + b + " and " + this.build);
      }
      if (r.build.number != b.number) {
        throw new IllegalStateException(r + " was attached to both " + b + " and " + r.build);
      }
      return r;
    }
  }
}
 
Example 4
Source File: TestResultProjectAction.java    From junit-plugin with MIT License 6 votes vote down vote up
public AbstractTestResultAction getLastTestResultAction() {
    final Run<?,?> tb = job.getLastSuccessfulBuild();

    Run<?,?> b = job.getLastBuild();
    while(b!=null) {
        AbstractTestResultAction a = b.getAction(AbstractTestResultAction.class);
        if(a!=null && (!b.isBuilding())) return a;
        if(b==tb)
            // if even the last successful build didn't produce the test result,
            // that means we just don't have any tests configured.
            return null;
        b = b.getPreviousBuild();
    }

    return null;
}
 
Example 5
Source File: TestResult.java    From junit-plugin with MIT License 6 votes vote down vote up
/**
 * Gets the counter part of this {@link TestResult} in the previous run.
 *
 * @return null if no such counter part exists.
 */
public TestResult getPreviousResult() {
    Run<?,?> b = getRun();
    if (b == null) {
        return null;
    }
    while(true) {
        b = b.getPreviousBuild();
        if(b==null)
            return null;
        AbstractTestResultAction r = b.getAction(getParentAction().getClass());
        if(r!=null) {
            TestResult result = r.findCorrespondingResult(this.getId());
            if (result!=null)
                return result;
        }
    }
}
 
Example 6
Source File: DecisionMaker.java    From office-365-connector-plugin with Apache License 2.0 5 votes vote down vote up
public DecisionMaker(Run run, TaskListener listener) {
    this.run = run;
    this.taskListener = listener;

    Run previousBuild = run.getPreviousBuild();
    previousResult = previousBuild != null ? previousBuild.getResult() : Result.SUCCESS;
}
 
Example 7
Source File: ZulipNotifier.java    From zulip-plugin with MIT License 5 votes vote down vote up
/**
 * Tests if the build should actually published<br/>
 * If SmartNotify is enabled, only notify if:
 * <ol>
 * <li>There was no previous build</li>
 * <li>The current build did not succeed</li>
 * <li>The previous build failed and the current build succeeded.</li>
 * </ol>
 *
 * @return true if build should be published
 */
private boolean shouldPublish(Run<?, ?> build) {
    if (SmartNotification.isSmartNotifyEnabled(smartNotification, DESCRIPTOR.isSmartNotify())) {
        Run<?, ?> previousBuild = build.getPreviousBuild();
        if (previousBuild == null ||
                getBuildResult(build) != Result.SUCCESS ||
                getBuildResult(previousBuild) != Result.SUCCESS) {
            return true;
        }
    } else {
        return true;
    }
    return false;
}