[Jenkins][ci skip]: Monitor jenkins queue build

This commit is contained in:
lm 2014-04-03 11:24:44 +08:00
parent f998ea058a
commit 7f1d694f03
1 changed files with 17 additions and 0 deletions

View File

@ -6,6 +6,21 @@ import os
import requests import requests
import sys import sys
import traceback import traceback
from jenkinsapi.jenkins import Jenkins
def check_queue_build(action, pr_num, statuses_url):
username = os.environ['JENKINS_ADMIN']
password = os.environ['JENKINS_ADMIN_PW']
J = Jenkins('http://115.28.134.83:8000',username,password)
queues = J.get_queue()
for key,queue in queues.iteritems():
q_payload_str = queue.get_parameters()['payload'].decode('utf-8','ignore')
q_payload = json.loads(q_payload_str)
q_pr_num = q_payload['number']
q_statuses_url = q_payload['statuses_url']
if(q_pr_num == pr_num):
if(action == 'closed') or (q_statuses_url != statuses_url):
queues.delete_item(queue)
def main(): def main():
#get payload from os env #get payload from os env
@ -40,6 +55,7 @@ def main():
target_url = os.environ['JOB_PULL_REQUEST_BUILD_URL'] target_url = os.environ['JOB_PULL_REQUEST_BUILD_URL']
if(action == 'closed'): if(action == 'closed'):
check_queue_build(action, pr_num, statuses_url)
print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered' print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered'
return(0) return(0)
@ -63,6 +79,7 @@ def main():
except: except:
traceback.print_exc() traceback.print_exc()
check_queue_build(action, pr_num, statuses_url)
job_trigger_url = os.environ['JOB_TRIGGER_URL'] job_trigger_url = os.environ['JOB_TRIGGER_URL']
#send trigger and payload #send trigger and payload
post_data = {'payload':""} post_data = {'payload':""}