@Override
 public Collection<? extends Action> getProjectActions(AbstractProject<?, ?> project) {
   // only allow the user to see the email template testing action if they can
   // configure the project itself.
   if (project.hasPermission(Permission.CONFIGURE)) {
     return Collections.singletonList(new EmailExtTemplateAction(project));
   }
   return Collections.EMPTY_LIST;
 }
Example #2
0
  /**
   * Actually build a project, passing in parameters where appropriate
   *
   * @param project
   * @return
   */
  protected final boolean performBuildProject(AbstractProject<?, ?> project) {
    if (!project.hasPermission(AbstractProject.BUILD)) {
      LOGGER.log(Level.WARNING, "Insufficient permission to build job '" + project.getName() + "'");
      return false;
    }

    if (action.equals(BuildAction.POLL_SCM)) {
      project.schedulePolling();
      return true;
    }

    // no user parameters provided, just build it
    if (param == null) {
      project.scheduleBuild(new Cause.UserIdCause());
      return true;
    }

    ParametersDefinitionProperty pp =
        (ParametersDefinitionProperty) project.getProperty(ParametersDefinitionProperty.class);

    // project does not except any parameters, just build it
    if (pp == null) {
      project.scheduleBuild(new Cause.UserIdCause());
      return true;
    }

    List<ParameterDefinition> parameterDefinitions = pp.getParameterDefinitions();
    List<ParameterValue> values = new ArrayList<ParameterValue>();

    for (ParameterDefinition paramDef : parameterDefinitions) {

      if (!(paramDef instanceof StringParameterDefinition)) {
        // TODO add support for other parameter types
        values.add(paramDef.getDefaultParameterValue());
        continue;
      }

      StringParameterDefinition stringParamDef = (StringParameterDefinition) paramDef;
      ParameterValue value;

      // Did user supply this parameter?
      if (param.containsKey(paramDef.getName())) {
        value = stringParamDef.createValue(param.get(stringParamDef.getName()));
      } else {
        // No, then use the default value
        value = stringParamDef.createValue(stringParamDef.getDefaultValue());
      }

      values.add(value);
    }

    Jenkins.getInstance().getQueue().schedule(pp.getOwner(), 1, new ParametersAction(values));
    return true;
  }
    public FormValidation doCheck(
        @AncestorInPath AbstractProject project, @QueryParameter String value) {
      // Require CONFIGURE permission on this project
      if (!project.hasPermission(Item.CONFIGURE)) return FormValidation.ok();

      for (String name : Util.tokenize(fixNull(value), ",")) {
        name = name.trim();
        if (Jenkins.getInstance().getItem(name, project) == null)
          return FormValidation.error(
              hudson.tasks.Messages.BuildTrigger_NoSuchProject(
                  name, AbstractProject.findNearest(name).getName()));
      }

      return FormValidation.ok();
    }