hudson.model.ParameterDefinition Java Examples
The following examples show how to use
hudson.model.ParameterDefinition.
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 |
/** * @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: ParametersDefinitionPropertyCoverter.java From DotCi with MIT License | 6 votes |
@Override public Object decode(Class targetClass, Object fromDBObject, MappedField optionalExtraInfo) { if (fromDBObject == null) return null; List<DBObject> list = (List) fromDBObject; List<ParameterDefinition> parameterDefinitions = new ArrayList<ParameterDefinition>(); // TODO parsing checks for (DBObject dbObject : list) { ParameterDefinition definition = (ParameterDefinition) getMapper() .fromDBObject(ParameterDefinition.class, dbObject, getMapper().createEntityCache()); parameterDefinitions.add(definition); } return new ParametersDefinitionProperty(parameterDefinitions); }
Example #3
Source File: GithubWebhook.java From DotCi with MIT License | 6 votes |
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 #4
Source File: GithubWebhookTest.java From DotCi with MIT License | 6 votes |
@Test public void should_trigger_build_with_default_parameter_values() throws IOException, InterruptedException { final StaplerRequest request = mock(StaplerRequest.class); when(request.getParameter("payload")).thenReturn("payload"); final DynamicProject project = mock(DynamicProject.class); final ParameterDefinition branchParameter = mock(ParameterDefinition.class); when(branchParameter.getName()).thenReturn("BRANCH"); final ParameterDefinition secondParameter = mock(ParameterDefinition.class); when(branchParameter.getName()).thenReturn("PARAM"); when(secondParameter.getDefaultParameterValue()).thenReturn(new StringParameterValue("PARAM", "meow")); final ParametersDefinitionProperty paramDefinition = mock(ParametersDefinitionProperty.class); when(paramDefinition.getParameterDefinitions()).thenReturn(Arrays.asList(branchParameter, secondParameter)); when(project.getProperty(ParametersDefinitionProperty.class)).thenReturn(paramDefinition); kickOffBuildTrigger(request, project); final ArgumentCaptor<ParametersAction> parametersCaptor = ArgumentCaptor.forClass(ParametersAction.class); verify(project).scheduleBuild(eq(0), any(GithubPushPullWebhookCause.class), parametersCaptor.capture()); final ParametersAction parametersAction = parametersCaptor.getValue(); Assert.assertTrue(parametersAction.getParameter("PARAM") instanceof StringParameterValue); Assert.assertEquals("meow", ((StringParameterValue) parametersAction.getParameter("PARAM")).value); }
Example #5
Source File: AbstractPipelineImpl.java From blueocean-plugin with MIT License | 5 votes |
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 #6
Source File: ParametersDefinitionPropertyCoverter.java From DotCi with MIT License | 5 votes |
@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 #7
Source File: PipelineStepImpl.java From blueocean-plugin with MIT License | 4 votes |
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 #8
Source File: IOpenShiftPluginDescriptor.java From jenkins-plugin with Apache License 2.0 | 4 votes |
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; }