您可以通过Hudson Remote access API 访问当前是否正在构建作业(也可以通过访问http://your-hudson-url/api 查看文档)。根据您的偏好,API 可以返回 XML、JSON 或 python 可读格式。
具体来说,您应该查看作业的 API。检查 API 中可用内容的最佳方法是查看您的服务器 http://your-hudson-url/job/<job name>/api/xml。每个作业都有一个 Hudson 正在跟踪的构建(和结果)列表。如果构建正在进行中,build/building 元素将包含true。
这是我的测试版本的一些示例 XML 输出,网址为 http://localhost:8080/job/Plotting build/api/xml?depth=1(请注意设置为 1 的深度参数,以便为您提供比默认值更多的详细信息):
<freeStyleProject>
<action/>
<description>An example of the plot plugin</description>
<displayName>Plotting build</displayName>
<name>Plotting build</name>
<url>http://localhost:8080/job/Plotting%20build/</url>
<buildable>true</buildable>
<build>
<action>
<cause>
<shortDescription>Started by user test</shortDescription>
<userName>test</userName>
</cause>
</action>
<building>false</building>
<duration>30291</duration>
<fullDisplayName>Plotting build #14</fullDisplayName>
<id>2010-10-29_16-14-02</id>
<keepLog>false</keepLog>
<number>14</number>
<result>SUCCESS</result>
<timestamp>1288394042180</timestamp>
<url>http://localhost:8080/job/Plotting%20build/14/</url>
<builtOn/>
<changeSet/>
</build>
<build>
...
我不知道让节点下线是否有任何影响。我想只要 Hudson 知道构建正在进行中,API 就会返回正确的信息,您可以定期轮询以检查最近的构建是否完成。
更新:或者,您可以使用 API 查询节点以查看它们是否处于空闲状态。但是,据我所知,Hudson API 并未在节点查询输出中显示正在运行的作业。
http://localhost:8080/computer/(master)/api/xml?depth=1 的示例输出
<masterComputer>
<displayName>master</displayName>
<executor>
<idle>true</idle>
<likelyStuck>false</likelyStuck>
<number>0</number>
<progress>-1</progress>
</executor>
...
<idle>true</idle>
...
如果作业正在运行,则 computer/idle 元素为 false。在撰写本文时,如果您在作业运行时请求depth=1,则Hudson bug 会导致无效响应(尽管默认深度将显示节点是否空闲)。
使用节点 API,您可以将节点离线(然后重新在线?)作为部署脚本的一部分。