public HttpResponse doCommenceLogin(
      StaplerRequest request, @Header("Referer") final String referer) throws IOException {

    request.getSession().setAttribute(REFERER_ATTRIBUTE, referer);

    Set<String> scopes = new HashSet<String>();
    for (GitHubOAuthScope s : Jenkins.getInstance().getExtensionList(GitHubOAuthScope.class)) {
      scopes.addAll(s.getScopesToRequest());
    }
    String suffix = "";
    if (!scopes.isEmpty()) {
      suffix = "&scope=" + Util.join(scopes, ",");
    }

    return new HttpRedirect(githubUri + "/login/oauth/authorize?client_id=" + clientID + suffix);
  }
  public Channel launchChannel(
      String[] cmd, OutputStream out, FilePath _workDir, Map<String, String> envVars)
      throws IOException, InterruptedException {
    printCommandLine(cmd, _workDir);

    try {
      Process proc = launcher.launch(Util.join(asList(cmd), " "), _workDir.getRemote());

      return new Channel(
          "channel over named pipe to " + launcher.getHostName(),
          Computer.threadPoolForRemoting,
          proc.getInputStream(),
          new BufferedOutputStream(proc.getOutputStream()));
    } catch (JIException e) {
      throw new IOException(e);
    }
  }
Exemplo n.º 3
0
  /**
   * Computes the list of other form fields that the given field depends on, via the doFillXyzItems
   * method, and sets that as the 'fillDependsOn' attribute. Also computes the URL of the
   * doFillXyzItems and sets that as the 'fillUrl' attribute.
   */
  public void calcFillSettings(String field, Map<String, Object> attributes) {
    String capitalizedFieldName = StringUtils.capitalize(field);
    String methodName = "doFill" + capitalizedFieldName + "Items";
    Method method = ReflectionUtils.getPublicMethodNamed(getClass(), methodName);
    if (method == null)
      throw new IllegalStateException(
          String.format(
              "%s doesn't have the %s method for filling a drop-down list",
              getClass(), methodName));

    // build query parameter line by figuring out what should be submitted
    List<String> depends = buildFillDependencies(method, new ArrayList<String>());

    if (!depends.isEmpty()) attributes.put("fillDependsOn", Util.join(depends, " "));
    attributes.put(
        "fillUrl",
        String.format(
            "%s/%s/fill%sItems",
            getCurrentDescriptorByNameUrl(), getDescriptorUrl(), capitalizedFieldName));
  }
  public Map<String, String> getJenkinsSystemVariables(boolean forceOnMaster)
      throws IOException, InterruptedException {

    Map<String, String> result = new TreeMap<String, String>();

    Computer computer;
    if (forceOnMaster) {
      computer = Hudson.getInstance().toComputer();
    } else {
      computer = Computer.currentComputer();
    }

    // test if there is at least one executor
    if (computer != null) {
      result = computer.getEnvironment().overrideAll(result);
      Node n = computer.getNode();
      if (n != null) result.put("NODE_NAME", computer.getName());
      result.put("NODE_LABELS", Util.join(n.getAssignedLabels(), " "));
    }

    String rootUrl = Hudson.getInstance().getRootUrl();
    if (rootUrl != null) {
      result.put("JENKINS_URL", rootUrl);
      result.put("HUDSON_URL", rootUrl); // Legacy compatibility
    }
    result.put("JENKINS_HOME", Hudson.getInstance().getRootDir().getPath());
    result.put("HUDSON_HOME", Hudson.getInstance().getRootDir().getPath()); // legacy compatibility

    List<EnvironmentVariablesNodeProperty> globalNodeProperties =
        Hudson.getInstance()
            .getGlobalNodeProperties()
            .getAll(EnvironmentVariablesNodeProperty.class);
    for (EnvironmentVariablesNodeProperty environmentVariablesNodeProperty : globalNodeProperties) {
      result.putAll(environmentVariablesNodeProperty.getEnvVars());
    }

    return result;
  }
Exemplo n.º 5
0
 /**
  * If the list of configured goals contain the "-P" option, return the configured profiles.
  * Otherwise null.
  */
 public String getProfiles() {
   return Util.join(getMavenArgument("-P", "--activate-profiles"), ",");
 }
Exemplo n.º 6
0
  @Override
  public Boolean isRevExcluded(
      GitSCM scm, GitClient git, GitChangeSet commit, TaskListener listener, BuildData buildData) {
    Collection<String> paths = commit.getAffectedPaths();
    if (paths.isEmpty()) { // nothing modified, so no need to compute any of this
      return true;
    }

    List<Pattern> included = getIncludedPatterns();
    List<Pattern> excluded = getExcludedPatterns();

    // Assemble the list of included paths
    List<String> includedPaths = new ArrayList<String>(paths.size());
    if (!included.isEmpty()) {
      for (String path : paths) {
        for (Pattern pattern : included) {
          if (pattern.matcher(path).matches()) {
            includedPaths.add(path);
            break;
          }
        }
      }
    } else {
      includedPaths.addAll(paths);
    }

    // Assemble the list of excluded paths
    List<String> excludedPaths = new ArrayList<String>();
    if (!excluded.isEmpty()) {
      for (String path : includedPaths) {
        for (Pattern pattern : excluded) {
          if (pattern.matcher(path).matches()) {
            excludedPaths.add(path);
            break;
          }
        }
      }
    }

    if (excluded.isEmpty() && !included.isEmpty() && includedPaths.isEmpty()) {
      listener
          .getLogger()
          .println(
              "Ignored commit "
                  + commit.getCommitId()
                  + ": No paths matched included region whitelist");
      return true;
    } else if (includedPaths.size() == excludedPaths.size()) {
      // If every affected path is excluded, return true.
      listener
          .getLogger()
          .println(
              "Ignored commit "
                  + commit.getCommitId()
                  + ": Found only excluded paths: "
                  + Util.join(excludedPaths, ", "));
      return true;
    }

    return null;
  }