Re: Modifying a builds parameters in a system Groovy script
There is now a replaceAction() where you can just pass a new action (Parameter) with the same name and it will replace it :) http://javadoc.jenkins-ci.org/hudson/model/Actionable.html#replaceAction%28hudson.model.Action%29 On Friday, August 3, 2012 at 5:52:17 PM UTC+2, Reuben Gow wrote: > > Hi, > > I have a job that takes a number of parameters (version_number, > release_number, branch etc). This build can be built in a number of ways, > some need to get the values of these parameters from other locations. the > different modes are: > > 1) Manually - Take the passed in parameters > 2) SCM Change - take the parameter values from the last successful build > of another job > 3) Timer - take the parameter values from the last successful build of > another job > 4) Upstream Job - take the parameters passed to it from the upstream job. > > 1 is obviously no problem, as is 4 with the use of the Parameterized build > plugin. > > I have written a Groovy script to retrieve the parameter values for cases > 2 and 3 but can't find a way to apply these values to the variables used in > the build step (execute shell ). I can create new parameters and access > these as variables but I don't really like this method as it makes my shell > script a bit ugly. > > Does anyone know how to overwrite parameter values from within the Groovy > script. > > Thanks > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/71918569-5106-4173-a58a-1128c54379f8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Modifying a builds parameters in a system Groovy script
Following Reuben's comments I came up a util function. Posting here so other people can see a working example. import hudson.model.* // sets build parameters based on the given map // only supports StringParameterValue def setBuildParameters(map) { def npl = new ArrayListStringParameterValue() for (e in map) { npl.add(new StringParameterValue(e.key.toString(), e.value.toString())) } 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) } -- 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.
Re: Modifying a builds parameters in a system Groovy script
I found a solution to this. You have to get the 'Actions' of the build using the getActions() call, find the ParametersAction and remove it, then create a new set of parameters and then add them as an Action. On Monday, 6 August 2012 11:43:00 UTC+1, Reuben Gow wrote: Hi Chris, I've tried out the EnvInject plugin but it doesn't seem to be able to overwrite existing variables. if I put: return [ SOME_NEW_VAR: blah ] then I can put the following the in the build step echo ${SOME_NEW_VAR} and get the correct value. However if I put: return [ version_number: blah ] where version_number is one of the build parameters the echo command returns the original passed in parameter. On Friday, 3 August 2012 17:38:32 UTC+1, cjo wrote: Have a look at the EnvInject Plugin[1], to see if you are able plug your script into it and get the correct results. look at Prepare an environment for the run section in the job config. The Evaluated Groovy script item might override them correctly. https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin Chris On Friday, August 3, 2012 4:52:17 PM UTC+1, Reuben Gow wrote: Hi, I have a job that takes a number of parameters (version_number, release_number, branch etc). This build can be built in a number of ways, some need to get the values of these parameters from other locations. the different modes are: 1) Manually - Take the passed in parameters 2) SCM Change - take the parameter values from the last successful build of another job 3) Timer - take the parameter values from the last successful build of another job 4) Upstream Job - take the parameters passed to it from the upstream job. 1 is obviously no problem, as is 4 with the use of the Parameterized build plugin. I have written a Groovy script to retrieve the parameter values for cases 2 and 3 but can't find a way to apply these values to the variables used in the build step (execute shell ). I can create new parameters and access these as variables but I don't really like this method as it makes my shell script a bit ugly. Does anyone know how to overwrite parameter values from within the Groovy script. Thanks
Re: Modifying a builds parameters in a system Groovy script
Hi Chris, I've tried out the EnvInject plugin but it doesn't seem to be able to overwrite existing variables. if I put: return [ SOME_NEW_VAR: blah ] then I can put the following the in the build step echo ${SOME_NEW_VAR} and get the correct value. However if I put: return [ version_number: blah ] where version_number is one of the build parameters the echo command returns the original passed in parameter. On Friday, 3 August 2012 17:38:32 UTC+1, cjo wrote: Have a look at the EnvInject Plugin[1], to see if you are able plug your script into it and get the correct results. look at Prepare an environment for the run section in the job config. The Evaluated Groovy script item might override them correctly. https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin Chris On Friday, August 3, 2012 4:52:17 PM UTC+1, Reuben Gow wrote: Hi, I have a job that takes a number of parameters (version_number, release_number, branch etc). This build can be built in a number of ways, some need to get the values of these parameters from other locations. the different modes are: 1) Manually - Take the passed in parameters 2) SCM Change - take the parameter values from the last successful build of another job 3) Timer - take the parameter values from the last successful build of another job 4) Upstream Job - take the parameters passed to it from the upstream job. 1 is obviously no problem, as is 4 with the use of the Parameterized build plugin. I have written a Groovy script to retrieve the parameter values for cases 2 and 3 but can't find a way to apply these values to the variables used in the build step (execute shell ). I can create new parameters and access these as variables but I don't really like this method as it makes my shell script a bit ugly. Does anyone know how to overwrite parameter values from within the Groovy script. Thanks