您的位置:首页 > 编程语言 > Python开发

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

2010-07-21 09:44 627 查看
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']
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐