Java Code Examples for hudson.model.ParametersDefinitionProperty#getParameterDefinitions()

The following examples show how to use hudson.model.ParametersDefinitionProperty#getParameterDefinitions() . 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 File: JobHelper.java    From github-integration-plugin with 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
Source File: GithubWebhook.java    From DotCi with 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 3
Source File: AbstractPipelineImpl.java    From blueocean-plugin with MIT License 5 votes vote down vote up
public static List<Object> getParameterDefinitions(Job job){
    ParametersDefinitionProperty pp = (ParametersDefinitionProperty) job.getProperty(ParametersDefinitionProperty.class);
    List<Object> pds = new ArrayList<>();
    if(pp != null){
        for(ParameterDefinition pd : pp.getParameterDefinitions()){
            pds.add(pd);
        }
    }
    return pds;
}
 
Example 4
Source File: ParametersDefinitionPropertyCoverter.java    From DotCi with MIT License 5 votes vote down vote up
@Override
public Object encode(Object value, MappedField optionalExtraInfo) {
    if (value == null) return null;

    ParametersDefinitionProperty parametersDefinitionProperty = (ParametersDefinitionProperty) value;

    BasicDBList parameters = new BasicDBList();
    for (ParameterDefinition definition : parametersDefinitionProperty.getParameterDefinitions()) {
        parameters.add(getMapper().toDBObject(definition));
    }

    return parameters;
}
 
Example 5
Source File: IOpenShiftPluginDescriptor.java    From jenkins-plugin with Apache License 2.0 4 votes vote down vote up
default EnvVars buildEnvVars() {
    EnvVars allOverrides = new EnvVars(EnvVars.masterEnvVars);
    // when running outside of an openshift pod, global env vars like
    // SKIP_TLS will not exist in master env vars
    if (Jenkins.getInstance().getGlobalNodeProperties() != null) {
        if (Jenkins.getInstance().getGlobalNodeProperties()
                .get(hudson.slaves.EnvironmentVariablesNodeProperty.class) != null) {
            if (Jenkins
                    .getInstance()
                    .getGlobalNodeProperties()
                    .get(hudson.slaves.EnvironmentVariablesNodeProperty.class)
                    .getEnvVars() != null) {
                allOverrides
                        .putAll(Jenkins
                                .getInstance()
                                .getGlobalNodeProperties()
                                .get(hudson.slaves.EnvironmentVariablesNodeProperty.class)
                                .getEnvVars());
            }
        }
    }
    String[] reqPieces = Stapler.getCurrentRequest().getRequestURI()
            .split("/");
    if (reqPieces != null && reqPieces.length > 2) {
        for (Job j : Jenkins.getInstance().getAllItems(Job.class)) {
            if (j.getName().equals(reqPieces[2])) {
                List<JobProperty> jps = j.getAllProperties();
                for (JobProperty jp : jps) {
                    if (jp instanceof ParametersDefinitionProperty) {
                        ParametersDefinitionProperty prop = (ParametersDefinitionProperty) jp;
                        for (ParameterDefinition param : prop
                                .getParameterDefinitions()) {
                            allOverrides.put(param.getName(), param
                                    .getDefaultParameterValue().getValue()
                                    .toString());
                        }
                    }
                }
            }
        }
    }
    return allOverrides;
}