Part of our CI/continuous-test system needs to re-deploy build/test 开发者_运维百科nodes. so far I'm marking them offline and then waiting for twice as long as a build usually takes...
which is not very elegant.How can I (after marking it offline) wait for a node to finish its current job(s)?
You can access whether a job is currently building through the Hudson Remote access API (also see documentation by accessing http://your-hudson-url/api
). Depending on your preference, the API can return XML, JSON or a python-readable format.
Specifically, you should look at the API for a job. The best way to check what's available in the API is to look at your server, http://your-hudson-url/job/<job name>/api/xml
. Each job has a list of the builds (and results) that Hudson is tracking. If a build is in progress, the build/building element will contain true
.
Here's some example XML output from a test build of mine, url http://localhost:8080/job/Plotting build/api/xml?depth=1
(note the depth parameter which is set to 1 to give you more detail than the default):
<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>
...
I don't know whether there is any impact to taking nodes offline. I imagine that as long as Hudson knows the build is in progress, the API will return the right information and you can periodically poll to check whether the most recent build is finished.
Update: Alternatively, you can use the API to query nodes to see whether they are idle. However, from what I can tell, the Hudson API does not show what job is running in the node query output.
Example output from 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>
...
The computer/idle element is false
if a job is running. As of this writing, there is a Hudson bug that causes an invalid response if you ask for depth=1
while a job is running (though the default depth will show whether the node is idle).
Using the node API, you may be able to take a node offline (and back online?) as part of your deployment script.
If your script is local to the machine, I suggest you use a more bandwidth-inefficient, processing-efficient way of doing it.
Using @Dave_Bacher as an example, I'd interact with the JSON version of the API by running a URL like so..
http://localhost:8080/job/Plotting build/api/json?depth=1&tree=builds[building,number]
Then all you have to do is quickly run through the JSON, find your build, determine if it's building=false or true and voila.
This reduced my script run time from 10.5s to less than a second.
精彩评论