如何以编程方式确定哪些Jenkins从节点已用于运行构建? [英] How to programmatically determine which Jenkins slave node has been used to run a build?
问题描述
让我们说,我已经配置了一个Jenkins作业,它可以在几个Jenkins从节点(例如Node1,Node2,Node3等)上运行。当一个构建启动时,Jenkins将选择一个可用的Jenkins slave来运行Build。
Let's says I have configured a Jenkins job which can run on a few Jenkins slave nodes (e.g. Node1, Node2, Node3, etc). When a build is started, Jenkins will select an available Jenkins slave to run the Build.
对于已经完成或正在运行的构建, Jenkins从节点已被用于运行Build?
For a Build which has completed, or is currently running, how to programmatically determine which Jenkins slave node has been used to run the Build?
推荐答案
您可以使用 Jenkins REST API 查询现有版本,假设您知道版本号:
You can use the Jenkins REST API to query an existing build assuming you know the build number:
http:// jenkins:8080 / job / JOB_NAME / 100 / api / json?pretty = true
builtOn
字段显示正在运行/运行构建的从属的名称。
The builtOn
field shows the name of the slave which is running/ran the build.
要仅检索JSON构建信息的几个字段,请使用树
参数:
To retrieve only a couple fields of the JSON build information, use the tree
parameter:
http:// jenkins:8080 / job / JOB_NAME / 100 / api / json?tree = id,timestamp,builtOn& pretty = true
这将返回类似的结果:
{
"id" : "2014-12-01_06-18-17",
"timestamp" : 1417443497917,
"builtOn" : "sdev05"
}
Jenkins UI中的大多数页面底部都有一个REST API 链接,以编程方式查询。
Most pages in the Jenkins UI have a REST API link at the bottom indicating they expose information that can be queried programmatically.
这篇关于如何以编程方式确定哪些Jenkins从节点已用于运行构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!