如何使用 Groovy API 检索 Jenkins 构建参数? [英] How to retrieve Jenkins build parameters using the Groovy API?
问题描述
我有一个使用 Perforce 插件的参数化作业,我想检索构建参数/属性以及由 Perforce 插件设置的 p4.change 属性.
I have a parameterized job that uses the Perforce plugin and would like to retrieve the build parameters/properties as well as the p4.change property that's set by the Perforce plugin.
如何使用 Jenkins Groovy API 检索这些属性?
How do I retrieve these properties with the Jenkins Groovy API?
推荐答案
关于参数:
先看看这个答案.要获取项目的所有构建的列表(根据该答案获得):
See this answer first. To get a list of all the builds for a project (obtained as per that answer):
project.builds
当您找到您的特定构建时,您需要获取 ParametersAction 类型的所有操作 与 build.getActions(hudson.model).ParametersAction)
.然后查询返回的对象以获取特定参数.
When you find your particular build, you need to get all actions of type ParametersAction with build.getActions(hudson.model.ParametersAction)
. You then query the returned object for your specific parameters.
关于 p4.change:我怀疑它也被存储为一个动作.在 Jenkins Groovy 控制台中获取包含 p4.change 的构建的所有操作并检查它们 - 它会让您知道在代码中查找什么.
Regarding p4.change: I suspect that it is also stored as an action. In Jenkins Groovy console get all actions for a build that contains p4.change and examine them - it will give you an idea what to look for in your code.
这篇关于如何使用 Groovy API 检索 Jenkins 构建参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!