Skip to content
Permalink
Browse files

[Fix JENKINS-30178] Add default parameters defined in the job

  • Loading branch information
fbelzunc authored and MarkEWaite committed Oct 13, 2015
1 parent 7bb68ef commit 0a661ceaa5da94e92df97a2220a792d1eaa34317
Showing with 45 additions and 3 deletions.
  1. +45 −3 src/main/java/hudson/plugins/git/GitStatus.java
@@ -206,7 +206,7 @@ public void writeBody(PrintWriter w) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Received notification for uri = " + uri + " ; sha1 = " + sha1 + " ; branches = " + Arrays.toString(branches));
}

List<ParameterValue> allBuildParameters = new ArrayList<ParameterValue>(buildParameters);
List<ResponseContributor> result = new ArrayList<ResponseContributor>();
// run in high privilege to see all the projects anonymous users don't see.
// this is safe because when we actually schedule a build, it's a build that can
@@ -278,13 +278,26 @@ public void writeBody(PrintWriter w) {
}
if (!branchFound) continue;
urlFound = true;

if (!(project instanceof AbstractProject && ((AbstractProject) project).isDisabled())) {
//JENKINS-30178 Add default parameters defined in the job
if (project instanceof Job) {
Set<String> buildParametersNames = new HashSet<String>();
for (ParameterValue parameterValue: allBuildParameters) {
buildParametersNames.add(parameterValue.getName());
}

List<ParameterValue> jobParametersValues = getDefaultParametersValues((Job) project);
for (ParameterValue defaultParameterValue : jobParametersValues) {
if (!buildParametersNames.contains(defaultParameterValue.getName())) {
allBuildParameters.add(defaultParameterValue);
}
}
}
if (!parametrizedBranchSpec && isNotEmpty(sha1)) {
LOGGER.info("Scheduling " + project.getFullDisplayName() + " to build commit " + sha1);
scmTriggerItem.scheduleBuild2(scmTriggerItem.getQuietPeriod(),
new CauseAction(new CommitHookCause(sha1)),
new RevisionParameterAction(sha1, matchedURL), new ParametersAction(buildParameters));
new RevisionParameterAction(sha1, matchedURL), new ParametersAction(allBuildParameters));
result.add(new ScheduledResponseContributor(project));
} else {
LOGGER.info("Triggering the polling of " + project.getFullDisplayName());
@@ -312,6 +325,35 @@ public void writeBody(PrintWriter w) {
}
}

/**
* Get the default parameters values from a job
*
*/
private ArrayList<ParameterValue> getDefaultParametersValues(Job<?,?> job) {
ArrayList<ParameterValue> defValues;
ParametersDefinitionProperty paramDefProp = job.getProperty(ParametersDefinitionProperty.class);

if (paramDefProp != null) {
List <ParameterDefinition> parameterDefinition = paramDefProp.getParameterDefinitions();
defValues = new ArrayList<ParameterValue>(parameterDefinition.size());

} else {
defValues = new ArrayList<ParameterValue>();
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;
}

/**
* A response contributor for triggering polling of a project.
*

0 comments on commit 0a661ce

Please sign in to comment.
You can’t perform that action at this time.