Exemple #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;
    }
Exemple #2
0
  /**
   * An attempt to generate at least semi-useful EnvVars for polling calls, based on previous build.
   * Cribbed from various places.
   */
  public static EnvVars getPollEnvironment(
      AbstractProject p, FilePath ws, Launcher launcher, TaskListener listener)
      throws IOException, InterruptedException {
    EnvVars env;

    AbstractBuild b = (AbstractBuild) p.getLastBuild();

    if (b != null) {
      Node lastBuiltOn = b.getBuiltOn();

      if (lastBuiltOn != null) {
        env = lastBuiltOn.toComputer().getEnvironment().overrideAll(b.getCharacteristicEnvVars());
      } else {
        env = new EnvVars(System.getenv());
      }

      String rootUrl = Hudson.getInstance().getRootUrl();
      if (rootUrl != null) {
        env.put("HUDSON_URL", rootUrl);
        env.put("BUILD_URL", rootUrl + b.getUrl());
        env.put("JOB_URL", rootUrl + p.getUrl());
      }

      if (!env.containsKey("HUDSON_HOME")) {
        env.put("HUDSON_HOME", Hudson.getInstance().getRootDir().getPath());
      }

      if (ws != null) {
        env.put("WORKSPACE", ws.getRemote());
      }

      p.getScm().buildEnvVars(b, env);

      StreamBuildListener buildListener =
          new StreamBuildListener((OutputStream) listener.getLogger());

      for (NodeProperty nodeProperty : Hudson.getInstance().getGlobalNodeProperties()) {
        Environment environment = nodeProperty.setUp(b, launcher, (BuildListener) buildListener);
        if (environment != null) {
          environment.buildEnvVars(env);
        }
      }

      if (lastBuiltOn != null) {
        for (NodeProperty nodeProperty : lastBuiltOn.getNodeProperties()) {
          Environment environment = nodeProperty.setUp(b, launcher, buildListener);
          if (environment != null) {
            environment.buildEnvVars(env);
          }
        }
      }

      EnvVars.resolve(env);
    } else {
      env = new EnvVars(System.getenv());
    }

    return env;
  }
Exemple #3
0
  /**
   * Creates an environment variable override to be used for launching processes on this node.
   *
   * @see ProcStarter#envs(Map)
   * @since 1.489
   */
  public EnvVars buildEnvironment(TaskListener listener) throws IOException, InterruptedException {
    EnvVars env = new EnvVars();

    Node node = getNode();
    if (node == null) return env; // bail out

    for (NodeProperty nodeProperty : Jenkins.getInstance().getGlobalNodeProperties()) {
      nodeProperty.buildEnvVars(env, listener);
    }

    for (NodeProperty nodeProperty : node.getNodeProperties()) {
      nodeProperty.buildEnvVars(env, listener);
    }

    // TODO: hmm, they don't really belong
    String rootUrl = Hudson.getInstance().getRootUrl();
    if (rootUrl != null) {
      env.put("HUDSON_URL", rootUrl); // Legacy.
      env.put("JENKINS_URL", rootUrl);
    }

    return env;
  }