Java Code Examples for hudson.model.ParameterValue

The following examples show how to use hudson.model.ParameterValue. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: github-integration-plugin   Source File: JobHelper.java    License: MIT License 6 votes vote down vote up
/**
 * @see jenkins.model.ParameterizedJobMixIn#getDefaultParametersValues()
 */
public static List<ParameterValue> getDefaultParametersValues(Job<?, ?> job) {
    ParametersDefinitionProperty paramDefProp = job.getProperty(ParametersDefinitionProperty.class);
    List<ParameterValue> defValues = new ArrayList<>();

    /*
     * This check is made ONLY if someone will call this method even if isParametrized() is false.
     */
    if (isNull(paramDefProp)) {
        return defValues;
    }

    /* Scan for all parameter with an associated default values */
    for (ParameterDefinition paramDefinition : paramDefProp.getParameterDefinitions()) {
        ParameterValue defaultValue = paramDefinition.getDefaultParameterValue();

        if (defaultValue != null) {
            defValues.add(defaultValue);
        }
    }

    return defValues;
}
 
Example 2
private DeployJobVariables extractDeployJobVariables(AbstractBuild build) {
    String environment = DeployJobVariablesBuilder.UNDEFINED;
    String version = DeployJobVariablesBuilder.UNDEFINED;
    List<ParametersAction> actionList = Util.filter(build.getAllActions(), ParametersAction.class);
    for (ParametersAction parametersAction : actionList) {
        List<ParameterValue> params = parametersAction.getParameters();
        for (ParameterValue parameterValue : params) {
            if (DashboardView.PARAM_ENVIRONMENT.equalsIgnoreCase((String) parameterValue.getName())) {
                environment = (String) parameterValue.getValue();
            }
            if (DashboardView.PARAM_VERSION.equalsIgnoreCase((String) parameterValue.getName())) {
                version = (String) parameterValue.getValue();
            }
        }
    }
    return DeployJobVariablesBuilder.createBuilder().version(version).environment(environment).build();
}
 
Example 3
/**
 * this method started out as hudson.model.AbstractProject.getDefaultParametersValues()
 * @param parameterValues 
 * @return the ParameterValues as set from the crontab row or their defaults
 */
@SuppressWarnings("unchecked")
private List<ParameterValue> configurePropertyValues(Map<String, String> parameterValues) {
	assert job != null : "job must not be null if this was 'started'";
	ParametersDefinitionProperty paramDefProp = (ParametersDefinitionProperty) job
			.getProperty(ParametersDefinitionProperty.class);
	ArrayList<ParameterValue> defValues = new ArrayList<ParameterValue>();

	/* Scan for all parameter with an associated default values */
	for (ParameterDefinition paramDefinition : paramDefProp.getParameterDefinitions()) {
		ParameterValue defaultValue = paramDefinition.getDefaultParameterValue();

		if (parameterValues.containsKey(paramDefinition.getName())) {
			ParameterizedStaplerRequest request = new ParameterizedStaplerRequest(
					parameterValues.get(paramDefinition.getName()));
			defValues.add(paramDefinition.createValue(request));
		} else if (defaultValue != null)
			defValues.add(defaultValue);
	}

	return defValues;
}
 
Example 4
Source Project: DotCi   Source File: GithubWebhook.java    License: MIT License 6 votes vote down vote up
private List<ParameterValue> getParametersValues(final Job job, final String branch) {
    final ParametersDefinitionProperty paramDefProp = (ParametersDefinitionProperty) job.getProperty(ParametersDefinitionProperty.class);
    final ArrayList<ParameterValue> defValues = new ArrayList<>();

    for (final ParameterDefinition paramDefinition : paramDefProp.getParameterDefinitions()) {
        if ("BRANCH".equals(paramDefinition.getName())) {
            final StringParameterValue branchParam = new StringParameterValue("BRANCH", branch);
            defValues.add(branchParam);
        } else {
            final ParameterValue defaultValue = paramDefinition.getDefaultParameterValue();
            if (defaultValue != null)
                defValues.add(defaultValue);
        }
    }

    return defValues;
}
 
Example 5
public BuildBeginInfo(String projectName, AbstractBuild<?, ?> build, NotificationConfig config){
    //获取请求参数
    List<ParametersAction> parameterList = build.getActions(ParametersAction.class);
    if(parameterList!=null && parameterList.size()>0){
        for(ParametersAction p : parameterList){
            for(ParameterValue pv : p.getParameters()){
                this.params.put(pv.getName(), pv.getValue());
            }
        }
    }
    //预计时间
    if(build.getProject().getEstimatedDuration()>0){
        this.durationTime = build.getProject().getEstimatedDuration();
    }
    //控制台地址
    StringBuilder urlBuilder = new StringBuilder();
    String jenkinsUrl = NotificationUtil.getJenkinsUrl();
    if(StringUtils.isNotEmpty(jenkinsUrl)){
        String buildUrl = build.getUrl();
        urlBuilder.append(jenkinsUrl);
        if(!jenkinsUrl.endsWith("/")){
            urlBuilder.append("/");
        }
        urlBuilder.append(buildUrl);
        if(!buildUrl.endsWith("/")){
            urlBuilder.append("/");
        }
        urlBuilder.append("console");
    }
    this.consoleUrl = urlBuilder.toString();
    //工程名称
    this.projectName = projectName;
    //环境名称
    if(config.topicName!=null){
        topicName = config.topicName;
    }
}
 
Example 6
@Override
public RebuildParameterPage getRebuildPage(ParameterValue parameterValue) {

    if (parameterValue instanceof ListGitBranchesParameterValue) {
        return new RebuildParameterPage(parameterValue.getClass(),"value.jelly");
    } else {
        return null;
    }
}
 
Example 7
Source Project: blueocean-plugin   Source File: RunContainerImpl.java    License: MIT License 5 votes vote down vote up
/**
 * Schedules a build. If build already exists in the queue and the pipeline does not
 * support running multiple builds at the same time, return a reference to the existing
 * build.
 *
 * @return Queue item.
 */
@Override
public BlueRun create(StaplerRequest request) {
    job.checkPermission(Item.BUILD);
    if (job instanceof Queue.Task) {
        ScheduleResult scheduleResult;

        List<ParameterValue> parameterValues = getParameterValue(request);
        int expectedBuildNumber = job.getNextBuildNumber();
        if(parameterValues.size() > 0) {
            scheduleResult = Jenkins.getInstance()
                    .getQueue()
                    .schedule2((Queue.Task) job, 0, new ParametersAction(parameterValues),
                            new CauseAction(new Cause.UserIdCause()));
        }else {
            scheduleResult = Jenkins.getInstance()
                    .getQueue()
                    .schedule2((Queue.Task) job, 0, new CauseAction(new Cause.UserIdCause()));
        }
        // Keep FB happy.
        // scheduleResult.getItem() will always return non-null if scheduleResult.isAccepted() is true
        final Queue.Item item = scheduleResult.getItem();
        if(scheduleResult.isAccepted() && item != null) {
            return new QueueItemImpl(
                pipeline.getOrganization(),
                item,
                pipeline,
                expectedBuildNumber, pipeline.getLink().rel("queue").rel(Long.toString(item.getId())),
                pipeline.getLink()
            ).toRun();
        } else {
            throw new ServiceException.UnexpectedErrorException("Queue item request was not accepted");
        }
    } else {
        throw new ServiceException.NotImplementedException("This pipeline type does not support being queued.");
    }
}
 
Example 8
Source Project: blueocean-plugin   Source File: PipelineStepImpl.java    License: MIT License 5 votes vote down vote up
private Object convert(String name, ParameterValue v) throws IOException, InterruptedException {
    if (v instanceof FileParameterValue) {
        FileParameterValue fv = (FileParameterValue) v;
        FilePath fp = new FilePath(node.getRun().getRootDir()).child(name);
        fp.copyFrom(fv.getFile());
        return fp;
    } else {
        return v.getValue();
    }
}
 
Example 9
@VisibleForTesting
static String getAbortOnRevisionId(AbstractBuild build) {
    ParametersAction parameters = build.getAction(ParametersAction.class);
    if (parameters != null) {
        ParameterValue parameterValue = parameters.getParameter(
                PhabricatorPlugin.ABORT_ON_REVISION_ID_FIELD);
        if (parameterValue != null) {
            return (String) parameterValue.getValue();
        }
    }
    return null;
}
 
Example 10
@Test
public void getAbortOnRevisionIdIfAvailable() throws Exception {
    FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, null, true);
    assertNull(PhabricatorBuildWrapper.getAbortOnRevisionId(build));

    List<ParameterValue> parameters = Lists.newArrayList();
    parameters.add(new ParameterValue("ABORT_ON_REVISION_ID") {
        @Override
        public Object getValue() {
            return "test";
        }
    });
    build.addAction(new ParametersAction(parameters));
    assertEquals("test", PhabricatorBuildWrapper.getAbortOnRevisionId(build));
}
 
Example 11
Source Project: github-integration-plugin   Source File: GitHubEnv.java    License: MIT License 5 votes vote down vote up
static <T extends GitHubCause<?>, X extends Enum<X> & GitHubEnv<T>> void getParams(Class<X> enumClass,
                                                                                   T cause,
                                                                                   List<ParameterValue> params) {
    for (GitHubEnv<T> env : enumClass.getEnumConstants()) {
        env.addParam(cause, params);
    }
}
 
Example 12
Source Project: github-integration-plugin   Source File: GitHubSCMSource.java    License: MIT License 5 votes vote down vote up
@Nonnull
@Override
protected List<Action> retrieveActions(@Nonnull SCMRevision revision, @CheckForNull SCMHeadEvent event,
                                       @Nonnull TaskListener listener) throws IOException, InterruptedException {
    GitHubSCMRevision gitHubSCMRevision = (GitHubSCMRevision) revision;
    GitHubCause<?> cause = gitHubSCMRevision.getCause();
    if (nonNull(cause)) {
        List<ParameterValue> params = new ArrayList<>();
        cause.fillParameters(params);
        return Arrays.asList(new CauseAction(cause), new GitHubParametersAction(params));
    }

    return Collections.emptyList();
}
 
Example 13
Source Project: github-integration-plugin   Source File: JobRunnerForCauseTest.java    License: MIT License 5 votes vote down vote up
public static QueueTaskFuture schedule(Job<?, ?> job, int number, String param, int queuetPeriod) {
    ParameterizedJobMixIn jobMixIn = JobInfoHelpers.asParameterizedJobMixIn(job);
    GitHubPRCause cause = newGitHubPRCause().withNumber(number);
    ParametersAction parametersAction = new ParametersAction(
            Collections.<ParameterValue>singletonList(new StringParameterValue("value", param))
    );
    return jobMixIn.scheduleBuild2(queuetPeriod, new CauseAction(cause), parametersAction);
}
 
Example 14
Source Project: flaky-test-handler-plugin   Source File: DeflakeAction.java    License: Apache License 2.0 5 votes vote down vote up
private static ParameterValue getBooleanParam(JSONObject formData, String paramName) {
  JSONObject paramObj = JSONObject.fromObject(formData.get(paramName));
  String name = paramObj.getString("name");
  FlakyTestResultAction.logger.log(Level.FINE,
      "Param: " + name + " with value: " + paramObj.getBoolean("value"));
  return new BooleanParameterValue(name, paramObj.getBoolean("value"));
}
 
Example 15
Source Project: flaky-test-handler-plugin   Source File: DeflakeAction.java    License: Apache License 2.0 5 votes vote down vote up
private static ParameterValue getStringParam(JSONObject formData, String paramName) {
  JSONObject paramObj = JSONObject.fromObject(formData.get(paramName));
  String name = paramObj.getString("name");
  FlakyTestResultAction.logger.log(Level.FINE,
      "Param: " + name + " with value: " + paramObj.getString("value"));
  return new StringParameterValue(name, paramObj.getString("value"));
}
 
Example 16
Source Project: DotCi   Source File: ProcessedBuild.java    License: MIT License 5 votes vote down vote up
@Override
public List<ParameterValue> getParameters() {
    if (this.build.getAction(ParametersAction.class) != null) {
        return this.build.getAction(ParametersAction.class).getParameters();
    }
    return Lists.newArrayList();
}
 
Example 17
Source Project: DotCi   Source File: DownstreamJobPlugin.java    License: MIT License 5 votes vote down vote up
private String getSourceBuildNumber(DynamicBuild dynamicBuild) {
    if (dynamicBuild.getCause() instanceof DotCiUpstreamTriggerCause) {
        List<ParameterValue> params = dynamicBuild.getAction(ParametersAction.class).getParameters();
        for (ParameterValue param : params) {
            if (param.getName().equals("SOURCE_BUILD")) {
                return (String) param.getValue();
            }
        }
    }
    return "" + dynamicBuild.getNumber();
}
 
Example 18
Source Project: DotCi   Source File: DownstreamJobPlugin.java    License: MIT License 5 votes vote down vote up
private NoDuplicatesParameterAction getParamsAction(Map<String, String> jobParams) {
    List<ParameterValue> params = new ArrayList<ParameterValue>();
    for (Map.Entry<String, String> entry : jobParams.entrySet()) {
        params.add(new StringParameterValue(entry.getKey(), entry.getValue()));
    }

    return new NoDuplicatesParameterAction(params);
}
 
Example 19
Source Project: blueocean-plugin   Source File: PipelineStepImpl.java    License: MIT License 4 votes vote down vote up
private Object parseValue(InputStepExecution execution, JSONArray parameters, StaplerRequest request) throws IOException, InterruptedException {
    Map<String, Object> mapResult = new HashMap<String, Object>();

    InputStep input = execution.getInput();
    for(Object o: parameters){
        JSONObject p = (JSONObject) o;
        String name = (String) p.get(NAME_ELEMENT);

        if(name == null){
            throw new ServiceException.BadRequestException("name is required parameter element");
        }

        ParameterDefinition d=null;
        for (ParameterDefinition def : input.getParameters()) {
            if (def.getName().equals(name))
                d = def;
        }
        if (d == null)
            throw new ServiceException.BadRequestException("No such parameter definition: " + name);

        ParameterValue v = d.createValue(request, p);
        if (v == null) {
            continue;
        }
        mapResult.put(name, convert(name, v));
    }
    // If a destination value is specified, push the submitter to it.
    String valueName = input.getSubmitterParameter();
    if (valueName != null && !valueName.isEmpty()) {
        Authentication a = Jenkins.getAuthentication();
        mapResult.put(valueName, a.getName());
    }
    switch (mapResult.size()) {
        case 0:
            return null;    // no value if there's no parameter
        case 1:
            return mapResult.values().iterator().next();
        default:
            return mapResult;
    }
}
 
Example 20
Source Project: github-integration-plugin   Source File: GitHubPRCause.java    License: MIT License 4 votes vote down vote up
@Override
public void fillParameters(List<ParameterValue> params) {
    GitHubPREnv.getParams(this, params);
}
 
Example 21
Source Project: github-integration-plugin   Source File: GitHubEnv.java    License: MIT License 4 votes vote down vote up
default ParameterValue param(String value) {
    return new StringParameterValue(toString(), escapeJava(trimToEmpty(value)));
}
 
Example 22
Source Project: github-integration-plugin   Source File: GitHubEnv.java    License: MIT License 4 votes vote down vote up
default ParameterValue param(boolean value) {
    return new BooleanParameterValue(toString(), value);
}
 
Example 23
Source Project: github-integration-plugin   Source File: GitHubTagCause.java    License: MIT License 4 votes vote down vote up
@Override
public void fillParameters(List<ParameterValue> params) {
    GitHubTagEnv.getParams(this, params);
}
 
Example 24
Source Project: github-integration-plugin   Source File: GitHubParametersAction.java    License: MIT License 4 votes vote down vote up
public GitHubParametersAction(List<ParameterValue> params) {
    this.params = params;
}
 
Example 25
Source Project: github-integration-plugin   Source File: GitHubBranchCause.java    License: MIT License 4 votes vote down vote up
@Override
public void fillParameters(List<ParameterValue> params) {
    GitHubBranchEnv.getParams(this, params);
}
 
Example 26
Source Project: DotCi   Source File: NoDuplicatesParameterAction.java    License: MIT License 4 votes vote down vote up
public NoDuplicatesParameterAction(List<ParameterValue> parametersValues) {
    super(parametersValues);
}
 
Example 27
Source Project: DotCi   Source File: QueuedBuild.java    License: MIT License 4 votes vote down vote up
@Override
public List<ParameterValue> getParameters() {
    return Lists.newArrayList();
}
 
Example 28
Source Project: DotCi   Source File: Build.java    License: MIT License 4 votes vote down vote up
@Exported
public abstract List<ParameterValue> getParameters();
 
Example 29
Source Project: github-integration-plugin   Source File: GitHubCause.java    License: MIT License votes vote down vote up
public abstract void fillParameters(List<ParameterValue> params); 
Example 30
Source Project: github-integration-plugin   Source File: GitHubEnv.java    License: MIT License votes vote down vote up
void addParam(T cause, List<ParameterValue> params);