示例#1
0
    /**
     * Creates a {@link Launcher} that this build will use. This can be overridden by derived types
     * to decorate the resulting {@link Launcher}.
     *
     * @param listener Always non-null. Connected to the main build output.
     */
    protected Launcher createLauncher(BuildListener listener)
        throws IOException, InterruptedException {
      Launcher l = getCurrentNode().createLauncher(listener);

      if (project instanceof BuildableItemWithBuildWrappers) {
        BuildableItemWithBuildWrappers biwbw = (BuildableItemWithBuildWrappers) project;
        for (BuildWrapper bw : biwbw.getBuildWrappersList())
          l = bw.decorateLauncher(AbstractBuild.this, l, listener);
      }

      buildEnvironments = new ArrayList<Environment>();

      for (NodeProperty nodeProperty : Hudson.getInstance().getGlobalNodeProperties()) {
        Environment environment = nodeProperty.setUp(AbstractBuild.this, l, listener);
        if (environment != null) {
          buildEnvironments.add(environment);
        }
      }

      for (NodeProperty nodeProperty : Computer.currentComputer().getNode().getNodeProperties()) {
        Environment environment = nodeProperty.setUp(AbstractBuild.this, l, listener);
        if (environment != null) {
          buildEnvironments.add(environment);
        }
      }

      return l;
    }
示例#2
0
 /**
  * Run preCheckout on {@link BuildWrapper}s
  *
  * @param launcher The launcher, never null.
  * @param listener Never null, connected to the main build output.
  * @throws IOException
  * @throws InterruptedException
  */
 private void preCheckout(Launcher launcher, BuildListener listener)
     throws IOException, InterruptedException {
   if (project instanceof BuildableItemWithBuildWrappers) {
     BuildableItemWithBuildWrappers biwbw = (BuildableItemWithBuildWrappers) project;
     for (BuildWrapper bw : biwbw.getBuildWrappersList())
       bw.preCheckout(AbstractBuild.this, launcher, listener);
   }
 }
示例#3
0
  protected List<Action> createTransientActions() {
    List<Action> r = super.createTransientActions();

    // Fix for ISSUE-1149
    for (MavenModule module : modules.values()) {
      module.updateTransientActions();
    }

    if (publishers
        != null) // this method can be loaded from within the onLoad method, where this might be
                 // null
    for (BuildStep step : publishers) r.addAll(step.getProjectActions(this));

    if (buildWrappers != null)
      for (BuildWrapper step : buildWrappers) r.addAll(step.getProjectActions(this));

    return r;
  }
示例#4
0
  /**
   * Provides additional variables and their values to {@link Builder}s.
   *
   * <p>This mechanism is used by {@link MatrixConfiguration} to pass the configuration values to
   * the current build. It is up to {@link Builder}s to decide whether it wants to recognize the
   * values or how to use them.
   *
   * <p>This also includes build parameters if a build is parameterized.
   *
   * @return The returned map is mutable so that subtypes can put more values.
   */
  public Map<String, String> getBuildVariables() {
    Map<String, String> r = new HashMap<String, String>();

    ParametersAction parameters = getAction(ParametersAction.class);
    if (parameters != null) {
      // this is a rather round about way of doing this...
      for (ParameterValue p : parameters) {
        String v = p.createVariableResolver(this).resolve(p.getName());
        if (v != null) r.put(p.getName(), v);
      }
    }

    // allow the BuildWrappers to contribute additional build variables
    if (project instanceof BuildableItemWithBuildWrappers) {
      for (BuildWrapper bw : ((BuildableItemWithBuildWrappers) project).getBuildWrappersList())
        bw.makeBuildVariables(this, r);
    }

    return r;
  }
示例#5
0
  /**
   * Builds up a set of variable names that contain sensitive values that should not be exposed. The
   * expection is that this set is populated with keys returned by {@link #getBuildVariables()} that
   * should have their values masked for display purposes.
   *
   * @since 1.378
   */
  public Set<String> getSensitiveBuildVariables() {
    Set<String> s = new HashSet<String>();

    ParametersAction parameters = getAction(ParametersAction.class);
    if (parameters != null) {
      for (ParameterValue p : parameters) {
        if (p.isSensitive()) {
          s.add(p.getName());
        }
      }
    }

    // Allow BuildWrappers to determine if any of their data is sensitive
    if (project instanceof BuildableItemWithBuildWrappers) {
      for (BuildWrapper bw : ((BuildableItemWithBuildWrappers) project).getBuildWrappersList()) {
        bw.makeSensitiveBuildVariables(this, s);
      }
    }

    return s;
  }
示例#6
0
文件: Build.java 项目: sbdash/hudson
    protected Result doRun(BuildListener listener) throws Exception {
      if (!preBuild(listener, project.getBuilders())) return FAILURE;
      if (!preBuild(listener, project.getPublishers())) return FAILURE;

      Result r = null;
      try {
        List<BuildWrapper> wrappers =
            new ArrayList<BuildWrapper>(project.getBuildWrappers().values());

        ParametersAction parameters = getAction(ParametersAction.class);
        if (parameters != null) parameters.createBuildWrappers(Build.this, wrappers);

        for (BuildWrapper w : wrappers) {
          Environment e = w.setUp((AbstractBuild<?, ?>) Build.this, launcher, listener);
          if (e == null) return (r = FAILURE);
          buildEnvironments.add(e);
        }

        if (!build(listener, project.getBuilders())) r = FAILURE;
      } catch (InterruptedException e) {
        r = ABORTED;
        throw e;
      } finally {
        if (r != null) setResult(r);
        // tear down in reverse order
        boolean failed = false;
        for (int i = buildEnvironments.size() - 1; i >= 0; i--) {
          if (!buildEnvironments.get(i).tearDown(Build.this, listener)) {
            failed = true;
          }
        }
        // WARNING The return in the finally clause will trump any return before
        if (failed) return FAILURE;
      }

      return r;
    }
示例#7
0
    protected Result doRun(BuildListener listener) throws Exception {
      // pick up a list of reporters to run
      reporters = getProject().createReporters();
      MavenModuleSet mms = getProject().getParent();
      if (debug) listener.getLogger().println("Reporters=" + reporters);

      for (BuildWrapper w : mms.getBuildWrappersList()) {
        Environment e = w.setUp(MavenBuild.this, launcher, listener);
        if (e == null) {
          return Result.FAILURE;
        }
        buildEnvironments.add(e);
      }

      EnvVars envVars = getEnvironment(listener); // buildEnvironments should be set up first

      MavenInstallation mvn = getProject().getParent().getMaven();

      mvn = mvn.forEnvironment(envVars).forNode(Computer.currentComputer().getNode(), listener);

      MavenInformation mavenInformation =
          getModuleRoot().act(new MavenVersionCallable(mvn.getHome()));

      String mavenVersion = mavenInformation.getVersion();

      LOGGER.fine(
          getFullDisplayName()
              + " is building with mavenVersion "
              + mavenVersion
              + " from file "
              + mavenInformation.getVersionResourcePath());

      boolean maven3orLater = MavenUtil.maven3orLater(mavenVersion);

      ProcessCache.MavenProcess process =
          MavenBuild.mavenProcessCache.get(
              launcher.getChannel(),
              listener,
              maven3orLater
                  ? new Maven3ProcessFactory(
                      getParent().getParent(),
                      launcher,
                      envVars,
                      getMavenOpts(listener, envVars),
                      null)
                  : new MavenProcessFactory(
                      getParent().getParent(),
                      launcher,
                      envVars,
                      getMavenOpts(listener, envVars),
                      null));

      ArgumentListBuilder margs = new ArgumentListBuilder("-N", "-B");
      FilePath localRepo = mms.getLocalRepository().locate(MavenBuild.this);
      if (localRepo != null)
        // the workspace must be on this node, so getRemote() is safe.
        margs.add("-Dmaven.repo.local=" + localRepo.getRemote());

      if (mms.getAlternateSettings() != null) {
        if (IOUtils.isAbsolute(mms.getAlternateSettings())) {
          margs.add("-s").add(mms.getAlternateSettings());
        } else {
          FilePath mrSettings = getModuleRoot().child(mms.getAlternateSettings());
          FilePath wsSettings = getWorkspace().child(mms.getAlternateSettings());
          if (!wsSettings.exists() && mrSettings.exists()) wsSettings = mrSettings;

          margs.add("-s").add(wsSettings.getRemote());
        }
      }

      margs.add("-f", getModuleRoot().child("pom.xml").getRemote());
      margs.addTokenized(getProject().getGoals());

      Map<String, String> systemProps = new HashMap<String, String>(envVars);
      // backward compatibility
      systemProps.put("hudson.build.number", String.valueOf(getNumber()));

      if (maven3orLater) {
        // FIXME here for maven 3 builds
        listener
            .getLogger()
            .println("Building single Maven modules is not implemented for Maven 3, yet!");
        return Result.ABORTED;
      } else {
        boolean normalExit = false;
        try {
          Result r =
              process.call(
                  new Builder(
                      listener, new ProxyImpl(), getProject(), margs.toList(), systemProps));
          normalExit = true;
          return r;
        } finally {
          if (normalExit) process.recycle();
          else process.discard();

          // tear down in reverse order
          boolean failed = false;
          for (int i = buildEnvironments.size() - 1; i >= 0; i--) {
            if (!buildEnvironments.get(i).tearDown(MavenBuild.this, listener)) {
              failed = true;
            }
          }
          // WARNING The return in the finally clause will trump any return before
          if (failed) return Result.FAILURE;
        }
      }
    }
    @Override
    protected Result doRun(final BuildListener listener) throws Exception {
      PrintStream logger = listener.getLogger();
      try {
        EnvVars envVars = getEnvironment(listener);

        Config config = IvyConfig.provider.getConfigById(project.getSettings());
        if (config != null) {
          FilePath tmp = getWorkspace().createTextTempFile("ivy", "xml", config.content);
          settings = tmp.getRemote();
          addAction(new CleanTempFilesAction(settings));

        } else {
          String settingsFile = project.getIvySettingsFile();
          if (settingsFile != null) {
            settings = getWorkspace().child(settingsFile).getRemote();
          }
        }

        if (!project.isAggregatorStyleBuild()) {
          // start module builds
          parseIvyDescriptorFiles(listener, logger, envVars);
          Set<IvyModule> triggeredModules = new HashSet<IvyModule>();
          if (!project.isIncrementalBuild() || IvyModuleSetBuild.this.getChangeSet().isEmptySet()) {
            for (IvyModule module : project.sortedActiveModules) {
              // Don't trigger builds if we've already triggered
              // one
              // of their dependencies.
              // It's safe to just get the direct dependencies
              // since
              // the modules are sorted in dependency order.
              List<AbstractProject> ups = module.getUpstreamProjects();
              boolean triggerBuild = true;
              for (AbstractProject upstreamDep : ups) {
                if (triggeredModules.contains(upstreamDep)) {
                  triggerBuild = false;
                  break;
                }
              }

              if (triggerBuild) {
                logger.println("Triggering " + module.getModuleName());
                module.scheduleBuild(
                    new ParameterizedUpstreamCause(
                        ((Run<?, ?>) IvyModuleSetBuild.this),
                        IvyModuleSetBuild.this.getActions(ParametersAction.class)));
              }
              triggeredModules.add(module);
            }
          } else {
            for (IvyModule module : project.sortedActiveModules) {
              // If there are changes for this module, add it.
              // Also add it if we've never seen this module
              // before,
              // or if the previous build of this module
              // failed or was unstable.
              boolean triggerBuild = false;
              if ((module.getLastBuild() == null)
                  || (!getChangeSetFor(module).isEmpty())
                  || (module.getLastBuild().getResult().isWorseThan(Result.SUCCESS))) {
                triggerBuild = true;
                List<AbstractProject> ups = module.getUpstreamProjects();
                for (AbstractProject upstreamDep : ups) {
                  if (triggeredModules.contains(upstreamDep)) {
                    triggerBuild = false;
                    triggeredModules.add(module);
                    break;
                  }
                }
              }

              if (triggerBuild) {
                logger.println("Triggering " + module.getModuleName());
                module.scheduleBuild(
                    new ParameterizedUpstreamCause(
                        ((Run<?, ?>) IvyModuleSetBuild.this),
                        IvyModuleSetBuild.this.getActions(ParametersAction.class)));
                triggeredModules.add(module);
              }
            }
          }
        } else {
          // do builds here
          try {
            List<BuildWrapper> wrappers = new ArrayList<BuildWrapper>();
            for (BuildWrapper w : project.getBuildWrappersList()) wrappers.add(w);
            ParametersAction parameters = getAction(ParametersAction.class);
            if (parameters != null)
              parameters.createBuildWrappers(IvyModuleSetBuild.this, wrappers);

            for (BuildWrapper w : wrappers) {
              Environment e = w.setUp(IvyModuleSetBuild.this, launcher, listener);
              if (e == null) return Result.FAILURE;
              buildEnvironments.add(e);
              e.buildEnvVars(envVars); // #3502: too late for
              // getEnvironment to do
              // this
            }

            if (!preBuild(listener, project.getPublishers())) return Result.FAILURE;

            Properties additionalProperties = null;
            if (project.isIncrementalBuild()) {
              parseIvyDescriptorFiles(listener, logger, envVars);
              List<String> changedModules = new ArrayList<String>();
              for (IvyModule m : project.sortedActiveModules) {
                // Check if incrementalBuild is selected and that
                // there are changes -
                // we act as if incrementalBuild is not set if there
                // are no changes.
                if (!IvyModuleSetBuild.this.getChangeSet().isEmptySet()) {
                  // If there are changes for this module, add it.
                  if (!getChangeSetFor(m).isEmpty()) {
                    changedModules.add(m.getModuleName().name);
                  }
                }
              }

              if (project.isAggregatorStyleBuild()) {
                additionalProperties = new Properties();
                additionalProperties.put(
                    project.getChangedModulesProperty() == null
                        ? "hudson.ivy.changedModules"
                        : project.getChangedModulesProperty(),
                    StringUtils.join(changedModules, ','));
              }
            }

            IvyBuilderType ivyBuilderType = project.getIvyBuilderType();
            hudson.tasks.Builder builder =
                ivyBuilderType.getBuilder(additionalProperties, null, buildEnvironments);
            logger.println(
                "Building project with " + ivyBuilderType.getDescriptor().getDisplayName());

            if (builder.perform(IvyModuleSetBuild.this, launcher, listener)) return Result.SUCCESS;

            return Result.FAILURE;
          } finally {
            // tear down in reverse order
            boolean failed = false;
            for (int i = buildEnvironments.size() - 1; i >= 0; i--) {
              if (!buildEnvironments.get(i).tearDown(IvyModuleSetBuild.this, listener)) {
                failed = true;
              }
            }
            buildEnvironments = null;
            // WARNING The return in the finally clause will trump
            // any return before
            if (failed) return Result.FAILURE;
          }
        }

        return null;
      } catch (AbortException e) {
        if (e.getMessage() != null) listener.error(e.getMessage());
        return Result.FAILURE;
      } catch (InterruptedIOException e) {
        e.printStackTrace(listener.error("Aborted Ivy execution for InterruptedIOException"));
        return Result.ABORTED;
      } catch (InterruptedException e) {
        e.printStackTrace(listener.error("Aborted Ivy execution for InterruptedException"));
        return Result.ABORTED;
      } catch (IOException e) {
        e.printStackTrace(listener.error(Messages.IvyModuleSetBuild_FailedToParseIvyXml()));
        return Result.FAILURE;
      } catch (RunnerAbortedException e) {
        return Result.FAILURE;
      } catch (RuntimeException e) {
        // bug in the code.
        e.printStackTrace(
            listener.error(
                "Processing failed due to a bug in the code. Please report this to [email protected]"));
        logger.println("project=" + project);
        logger.println("project.getModules()=" + project.getModules());
        throw e;
      }
    }