I did find a solution, though not an explanation of why my original code didn't work. After viewing the source code for createUpdated, I wrote Groovy code to perform the same steps. Here's my working function to update the Jenkins parameters for a job while it is running. Existing parameters will be updated, and new parameters will be added to the job.

import hudson.model.*
def setBuildParameters(parmMap) {
  def npl = new ArrayList<StringParameterValue>()
  for (k in parmMap.keySet()) {
     npl.add(new StringParameterValue(k, parmMap.get(k)))
  }
  def newPa = null
  def oldPa = build.getAction(ParametersAction.class)

  if (oldPa != null) {
    for (oldp in oldPa) {
if (! parmMap.containsKey(oldp.name)) { // if oldp was not overridden by the new list npl.add(oldp) // then add it to the new list
      }
    }
    build.actions.remove(oldPa)
  }
  newPa = new ParametersAction(npl)
  build.actions.add(newPa)
}

Notes: This code was run as a System Groovy Script build step. As written it only covers String parameters.

-Eric

On 12/12/2013 1:27 PM, Eric Pyle wrote:
I am using Groovy to try to update an existing build parameter. I based my work on this example <https://groups.google.com/forum/#%21topic/jenkinsci-users/szhuDfCvpiE> from this list. However, I am getting an error saying my argument types are incorrect. Here's my code and the output from running it as a system Groovy script build step in Jenkins 1.509.4 on Win 7, with parameter INSTALL_HOME defined in the job with no default:

import hudson.model.*

def npl = new ArrayList<StringParameterValue>();
npl.add(new StringParameterValue("INSTALL_HOME", "/home/test/install/my_install"));

def newPa = null;
def oldPa = build.getAction(ParametersAction.class);
if (oldPa != null) {
  build.actions.remove(oldPa);
  newPa = oldPa.createUpdated(npl);
} else {
  newPa = new ParametersAction(npl);
}
build.actions.add(newPa);

======= output ===========================
Started by useranonymous  <http://localhost:8080/user/null>
Building in workspace C:\Users\ericp\.hudson\jobs\eric_test3\workspace
FATAL: No signature of method: hudson.model.ParametersAction.createUpdated() is 
applicable for argument types: (java.util.ArrayList) values: 
[[(StringParameterValue) INSTALL_HOME='/home/test/install/my_install']]
groovy.lang.MissingMethodException  
<http://stacktrace.jenkins-ci.org/search?query=groovy.lang.MissingMethodException>:
 No signature of method: hudson.model.ParametersAction.createUpdated() is applicable 
for argument types: (java.util.ArrayList) values: [[(StringParameterValue) 
INSTALL_HOME='/home/test/install/my_install']]
        
atorg.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55) 
 
<http://stacktrace.jenkins-ci.org/search/?query=org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap&entity=method>
        
atorg.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)  
<http://stacktrace.jenkins-ci.org/search/?query=org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call&entity=method>
        
atorg.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)  
<http://stacktrace.jenkins-ci.org/search/?query=org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall&entity=method>

This does not make sense. It says right in the error message that I'm calling createUpdated with argument of type ArrayList, containing values of type StringParameterValue, and the declaration of method createUpdated is:
public ParametersAction createUpdated(Collection<? extends ParameterValue> 
overrides)
Any idea what's going on?

Thanks,
Eric

--
You received this message because you are subscribed to the Google Groups "Jenkins 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to