This script will demonstrate how to get parameters in a system groovy script.
If you are using the Groovy plugin and want to leverage parameters for your system script, here are some tips.
import hudson.model.* // get current thread / Executor def thr = Thread.currentThread() // get current build def build = thr?.executable // get parameters def parameters = build?.actions.find{ it instanceof ParametersAction }?.parameters parameters.each { println "parameter ${it.name}:" println it.dump() println "-" * 80 } // ... or if you want the parameter by name ... def hardcoded_param = "FOOBAR" def resolver = build.buildVariableResolver def hardcoded_param_value = resolver.resolve(hardcoded_param) println "param ${hardcoded_param} value : ${hardcoded_param_value}"
this produces the output:
Started by user dnozay parameter RUNparam: <hudson.model.RunParameterValue@62042521 runId=broker_debug#1 name=RUNparam description=> -------------------------------------------------------------------------------- parameter CHOICEparam: <hudson.model.StringParameterValue@c4a75e7b value=foo name=CHOICEparam description=> -------------------------------------------------------------------------------- parameter FOOBAR: <hudson.model.StringParameterValue@dde4de51 value=<3 lolcats name=FOOBAR description=> -------------------------------------------------------------------------------- param FOOBAR value : <3 lolcats Finished: SUCCESS
3 Comments
Unknown User (wernight)
Nice script. This kind of stuff should definitely be on the plugin Wiki (getting/setting parameters or environment variables).
From the code I wonder how it can work safely with multiple nodes.
Unknown User (giladba)
Not working for non-system groovy script
Unknown User (jplandolt)
This script is great for showing the parameters passed to the build. Is it possible to use Groovy to list all of the options, not the final result, that were available for the param?
For example, Rather than get the returned value for "AppVersion", I want to have Groovy gather all choices from the ArrayList: