Python sample code of hudson remote api, my first Python hello world

来源:互联网 发布:淘宝刷钻助理 编辑:程序博客网 时间:2024/06/06 23:50
refer http://wiki.hudson-ci.org/display/HUDSON/Remote+access+API for more about hudson remote api

#!/usr/bin/env python

# this script is only demo purpose which is designed to get properties of job, queue, like
# nextBuildNumber. But note the logistics might not be correct

import urllib2

#call api of job 'git_plugin_test'
url="http://localhost:9001/job/git_plugin_test/api/python?depth=0"
response=urllib2.urlopen(url)
build_dict=eval(response.read())

#call api of job 'queue' of hudson (global but not specific for one job)
url="http://localhost:9001/queue/api/python?depth=0"
response=urllib2.urlopen(url)
queue_dict=eval(response.read())

print ''*40,'build dict',''*40
#print properties of job
for eachKey in build_dict:
    print eachKey,build_dict[eachKey]
    print

print ''*40,'queue dict',''*40
#look through items in queue and can be extended to forecast the job build
#number in for one item in queue
for index in range(1,len(queue_dict['items'])):
    print ''*40,'queue hash',''*40
    qi_action=queue_dict['items'][index]['actions']
    list_para=qi_action[0]['parameters']
    for index1 in range(0,len(list_para)):
        print list_para[index1]
        if list_para[index1]['name'] == 'SLEEP_TIME' and list_para[index1]['value'] == '62':
            print "OK"

#only valid when no more than one build found in queue
if build_dict['inQueue']:
    build_number=int(build_dict['nextBuildNumber']) + 1
else:
    build_number=int(build_dict['nextBuildNumber'])
print "Hudson Build URL:",build_dict['url']+str(build_number)
print "Current build tree:"+build_dict['builds'][0]['url']

原创粉丝点击