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

本文提供了一个使用Python脚本获取Hudson CI远程访问API的示例,包括如何调用job和队列API,解析返回的数据,并进行简单的数据处理。主要关注于API的基本使用和数据解析,旨在帮助用户快速上手Hudson CI的远程访问功能。
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']

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值