问题
In Groovy, I get my hands on a Hudson job:
def job = hudson.model.Hudson.instance.getItem("Rsync library to docs-stage")
Now I would like to have a list of the parameter names for that job. Sounds simple, but Googling around isn't getting me there yet. Could someone enlighten me?
Thanks.
回答1:
I'n not sure what you mean by "parameter names." As a last resort, you can get the configuration of the job as an XML String:
print job.configFile.asString()
Since this is XML, you can parse it as needed. Depending on what parameter names you are looking for, you can probably also get them directly in Java. Can you post the XML for what you are looking for? That will help in commenting on a better way.
For the parameters needed by this poster, it is easy to get using Groovy:
def params = job.getProperty('hudson.model.ParametersDefinitionProperty')
.parameterDefinitions
params.each { p -> println "$p.name"}
来源:https://stackoverflow.com/questions/29954975/in-groovy-how-do-i-get-the-list-of-parameter-names-for-a-given-job