timja / jenkins-gh-issues-poc-06-18

0 stars 0 forks source link

[JENKINS-7162] specifying a cli parameter causes unspecified parameters to be blank #871

Closed timja closed 12 years ago

timja commented 14 years ago

If you have a parameterized job with multiple parameters, all with default values, you can trigger it via an upstream build and all parameters have the default value as expected. This also works when building it via the CLI if you don't specify parameters.

However as soon as you specify one parameter like "-p PARAM1=foo" then all the other parameters lose their default value and are blank for the build.

I would expect that specifying one parameter should still allow others to get the default, otherwise in our scripts that invoke CLI builds, we have to put in every parameter and duplicate the default value which is error-prone and is easy to forget when changing one. Confirmed with a fresh and clean 1.370 Hudson.


Originally reported by mcrooney, imported from: specifying a cli parameter causes unspecified parameters to be blank
  • status: Closed
  • priority: Major
  • resolution: Fixed
  • resolved: 2012-08-15T11:45:47+00:00
  • imported: 2022/01/10
timja commented 14 years ago

mcrooney:

I did some poking around, and it appears that the culprit is AbstractProject.scheduleBuild2. It takes a list of Actions and if it gets any parameters, only uses those, and if it doesn't get ANY, it gets all the defaults. So in there it should probably get all the defaults, then merge into that any parameters specified.

timja commented 14 years ago

mcrooney:

Here is my attempt at a patch for as much as I could understand, though it still isn't doing the actual merging.

timja commented 14 years ago

mcrooney:

Unfortunately the half-written patch is as much as I can understand about the build/parameter process, so if anyone is able to finish it (I think it just needs to do the merging which is over my head), that would be greatly appreciated, otherwise I am unable to fix it.

timja commented 14 years ago

dogfood:

Integrated in hudson_main_trunk #200
[FIXED-JENKINS-7162]
Hudson ignores Maven pom.xml path when it is specified as absolute path.
Provided utility methods for checking whether a path is absolute and
absolutizing a given path (w.r.t. a base).
Provided a unit test case for this scenario (@Bug 7261).

km :
Files :

timja commented 14 years ago

mcrooney:

Hm, I'm pretty sure that comment is completely irrelevant.

timja commented 12 years ago

dannystaple:

This also affects the SSH cli access.
#JENKINS-11691 looks like a duplicate of this.

timja commented 12 years ago

dannystaple:

Oh and the dogfood comment about integrating a patch is most certainly not mcrooney's patch. As mcrooney mentions - it is a completely different patch for #JENKINS-7261.

timja commented 12 years ago

cjo9900:

As parameters are handled in the own page in the UI, which creates the ParametersAction with all of the displayed items including the defaults that are populated there is no problem.

From the CLI code it is a different case.

Just had a look at the code in the BuildCommand.java [1], and in this case it just checks that the parameter name passed in is correct, there is no checking of all the parameter definitions that are attached to the project to get the missing entries.

for (Entry e : parameters.entrySet())

{ String name = e.getKey(); ParameterDefinition pd = pdp.getParameterDefinition(name); if (pd==null) throw new AbortException(String.format("\'%s\' is not a valid parameter. Did you mean %s?", name, EditDistance.findNearest(name, pdp.getParameterDefinitionNames()))); values.add(pd.createValue(this,e.getValue())); }

a = new ParametersAction(values);

This should add the missing parameters using the default values.

[1] https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/cli/BuildCommand.java#L100

timja commented 12 years ago

cjo9900:

Pull request PULL 540 added to fix this.[1]

Add all the job defined Parameters to the ParameterAction using Defaults
if not passed via the command line.

If this breaks backwards compatibility where these are not expected to be passed, we can introduce a new option to use the defaults for parameters which triggers this behaviour.

@Option(name="-d",usage="Use defaults for parameters not specified, only valid when -p is used")
public boolean parameterDefaults = false;

[1] https://github.com/jenkinsci/jenkins/pull/540

timja commented 12 years ago

scm_issue_link:

Code changed in jenkins
User: c3johnso
Path:
core/src/main/java/hudson/cli/BuildCommand.java
test/src/test/groovy/hudson/cli/BuildCommandTest.groovy
http://jenkins-ci.org/commit/jenkins/7e0d7c0acba504b8bd205cdb228346bbfa09ddfa
Log:
[FIXED JENKINS-7162] Add missing parameters as defaults when called from CLI

Add all the job defined Parameters to the ParameterAction using Defaults
if not passed via the command line.

timja commented 12 years ago

scm_issue_link:

Code changed in jenkins
User: vjuranek
Path:
core/src/main/java/hudson/cli/BuildCommand.java
test/src/test/groovy/hudson/cli/BuildCommandTest.groovy
http://jenkins-ci.org/commit/jenkins/0ddceed69f86e1e32281561873483c4dbc6ee4dd
Log:
Merge pull request #540 from cjo9900/JENKINS-7162

[FIXED JENKINS-7162] Add missing parameters as defaults when called from...

Compare: https://github.com/jenkinsci/jenkins/compare/c14c7619c615...0ddceed69f86

timja commented 12 years ago

dogfood:

Integrated in jenkins_main_trunk #1856
[FIXED JENKINS-7162] Add missing parameters as defaults when called from CLI (Revision 7e0d7c0acba504b8bd205cdb228346bbfa09ddfa)

Result = UNSTABLE
chris.3.johnson : 7e0d7c0acba504b8bd205cdb228346bbfa09ddfa
Files :

timja commented 11 years ago

jmechler:

Would love to see this backported to LTS.

timja commented 2 years ago

[Originally duplicated by: JENKINS-11691]