Beispiel #1
0
  @Override
  protected Set<ResourceActivity> getResourceActivities() {
    final Set<ResourceActivity> activities = new HashSet<ResourceActivity>();

    activities.addAll(super.getResourceActivities());
    activities.addAll(Util.filter(publishers, ResourceActivity.class));
    activities.addAll(Util.filter(buildWrappers, ResourceActivity.class));

    return activities;
  }
Beispiel #2
0
  @Override
  public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedException {
    EnvVars env = super.getEnvironment(log);
    FilePath ws = getWorkspace();
    if (ws
        != null) // if this is done very early on in the build, workspace may not be decided yet.
                 // see HUDSON-3997
    env.put("WORKSPACE", ws.getRemote());
    // servlet container may have set CLASSPATH in its launch script,
    // so don't let that inherit to the new child process.
    // see http://www.nabble.com/Run-Job-with-JDK-1.4.2-tf4468601.html
    env.put("CLASSPATH", "");

    JDK jdk = project.getJDK();
    if (jdk != null) {
      Computer computer = Computer.currentComputer();
      if (computer != null) { // just in case were not in a build
        jdk = jdk.forNode(computer.getNode(), log);
      }
      jdk.buildEnvVars(env);
    }
    project.getScm().buildEnvVars(this, env);

    if (buildEnvironments != null) for (Environment e : buildEnvironments) e.buildEnvVars(env);

    for (EnvironmentContributingAction a :
        Util.filter(getActions(), EnvironmentContributingAction.class)) a.buildEnvVars(this, env);

    EnvVars.resolve(env);

    return env;
  }
  protected UserDetails retrieveUser(
      String username, UsernamePasswordAuthenticationToken authentication)
      throws AuthenticationException {
    try {
      // this is more seriously error, indicating a failure to search
      List<BadCredentialsException> errors = new ArrayList<BadCredentialsException>();

      // this is lesser error, in that we searched and the user was not found
      List<UsernameNotFoundException> notFound = new ArrayList<UsernameNotFoundException>();

      for (String domainName : domainNames) {
        try {
          return retrieveUser(username, authentication, domainName);
        } catch (UsernameNotFoundException e) {
          notFound.add(e);
        } catch (BadCredentialsException bce) {
          LOGGER.log(
              Level.WARNING,
              "Credential exception trying to authenticate against " + domainName + " domain",
              bce);
          errors.add(bce);
        }
      }

      switch (errors.size()) {
        case 0:
          break; // fall through
        case 1:
          throw errors.get(0); // preserve the original exception
        default:
          throw new MultiCauseBadCredentialsException(
              "Either no such user '" + username + "' or incorrect password", errors);
      }

      if (notFound.size() == 1) throw notFound.get(0); // preserve the original exception

      if (!Util.filter(notFound, UserMayOrMayNotExistException.class).isEmpty())
        // if one domain responds with UserMayOrMayNotExistException, then it might actually exist
        // there,
        // so our response will be "can't tell"
        throw new MultiCauseUserNotFoundException(
            "We can't tell if the user exists or not: " + username, notFound);

      if (!notFound.isEmpty())
        throw new MultiCauseUserNotFoundException("No such user: "******"no domain is configured");
    } catch (AuthenticationException e) {
      LOGGER.log(Level.FINE, "Failed toretrieve user " + username, e);
      throw e;
    }
  }
  /**
   * Schedules the given configuration.
   *
   * <p>Copied from the {@link
   * DefaultMatrixExecutionStrategyImpl#scheduleConfigurationBuild(hudson.matrix.MatrixBuild.MatrixBuildExecution,
   * hudson.matrix.MatrixConfiguration)}
   *
   * @param execution Contains information about the general build, including the listener used to
   *     log queue blockage.
   * @param configuration The configuration to schedule.
   * @param upstreamCause The cause of the build. Will either be an {@link
   *     hudson.model.Cause.UpstreamCause} or {@link
   *     com.attask.jenkins.healingmatrixproject.SelfHealingCause}.
   */
  private void scheduleConfigurationBuild(
      MatrixBuild.MatrixBuildExecution execution,
      MatrixConfiguration configuration,
      Cause.UpstreamCause upstreamCause)
      throws InterruptedException {
    MatrixBuild build = (MatrixBuild) execution.getBuild();
    execution
        .getListener()
        .getLogger()
        .println(Messages.MatrixBuild_Triggering(ModelHyperlinkNote.encodeTo(configuration)));

    // filter the parent actions for those that can be passed to the individual jobs.
    List<MatrixChildAction> childActions = Util.filter(build.getActions(), MatrixChildAction.class);

    BuildListener listener = execution.getListener();
    while (!configuration.scheduleBuild(childActions, upstreamCause)) {
      String msg = "Unable to schedule build " + configuration.getFullDisplayName() + ". Retrying.";
      listener.error(msg);
      Thread.sleep(500);
    }
  }
Beispiel #5
0
 /** Gets the snapshot of {@link Runner}s that are performing polling. */
 public List<Runner> getRunners() {
   return Util.filter(queue.getInProgress(), Runner.class);
 }
    @Override
    public boolean shouldTriggerBuild(
        AbstractBuild build, TaskListener listener, List<Action> actions) {
      /**
       * Schedules all the downstream builds. Returns immediately if build result doesn't meet the
       * required level (as specified by {@link BuildTrigger}, or {@link Result#SUCCESS} if none).
       *
       * @param listener Where the progress reports go.
       */
      if (build.getResult().isWorseThan(Result.SUCCESS)) return false;
      // trigger dependency builds
      AbstractProject<?, ?> downstreamProject = getDownstreamProject();
      if (AbstractMavenBuild.debug)
        listener
            .getLogger()
            .println("Considering whether to trigger " + downstreamProject + " or not");

      // if the downstream module depends on multiple modules,
      // only trigger them when all the upstream dependencies are updated.
      boolean trigger = true;

      // Check to see if any of its upstream dependencies are already building or in queue.
      AbstractMavenProject<?, ?> parent = (AbstractMavenProject<?, ?>) getUpstreamProject();
      if (areUpstreamsBuilding(downstreamProject, parent)) {
        if (AbstractMavenBuild.debug)
          listener
              .getLogger()
              .println(" -> No, because downstream has dependencies already building or in queue");
        trigger = false;
      }
      // Check to see if any of its upstream dependencies are in this list of downstream projects.
      else if (inDownstreamProjects(downstreamProject)) {
        if (AbstractMavenBuild.debug)
          listener
              .getLogger()
              .println(
                  " -> No, because downstream has dependencies in the downstream projects list");
        trigger = false;
      } else {
        AbstractBuild<?, ?> dlb = downstreamProject.getLastBuild(); // can be null.
        for (AbstractMavenProject up :
            Util.filter(downstreamProject.getUpstreamProjects(), AbstractMavenProject.class)) {
          Run ulb;
          if (up == parent) {
            // the current build itself is not registered as lastSuccessfulBuild
            // at this point, so we have to take that into account. ugly.
            if (build.getResult() == null || !build.getResult().isWorseThan(Result.UNSTABLE))
              ulb = build;
            else ulb = up.getLastSuccessfulBuild();
          } else ulb = up.getLastSuccessfulBuild();
          if (ulb == null) {
            // if no usable build is available from the upstream,
            // then we have to wait at least until this build is ready
            if (AbstractMavenBuild.debug)
              listener
                  .getLogger()
                  .println(
                      " -> No, because another upstream "
                          + up
                          + " for "
                          + downstreamProject
                          + " has no successful build");
            trigger = false;
            break;
          }

          // if no record of the relationship in the last build
          // is available, we'll just have to assume that the condition
          // for the new build is met, or else no build will be fired forever.
          if (dlb == null) continue;
          int n = dlb.getUpstreamRelationship(up);
          if (n == -1) continue;

          assert ulb.getNumber() >= n;
        }
      }
      return trigger;
    }