在Groovy中,如何获取给定作业的参数名称列表? [英] In Groovy, how do I get the list of parameter names for a given job?

查看:136
本文介绍了在Groovy中,如何获取给定作业的参数名称列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Groovy中,我开始从事Hudson的工作:

In Groovy, I get my hands on a Hudson job:

def job = hudson.model.Hudson.instance.getItem("Rsync library to docs-stage") 

现在,我想获得该作业的参数名称列表.听起来很简单,但是Google周围的搜索功能还无法解决我的问题.有人可以启发我吗?

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?

谢谢.

推荐答案

我不确定您所说的参数名称"是什么意思.作为最后的选择,您可以将作业配置为XML字符串:

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()

由于这是XML,因此您可以根据需要进行解析.根据您要查找的参数名称,您可能还可以直接在Java中获取它们.您可以为您要查找的内容发布XML吗?这将有助于以更好的方式发表评论.

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.

对于此海报所需的参数,可以很容易地使用Groovy:

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"}

这篇关于在Groovy中,如何获取给定作业的参数名称列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆