From 7f1d694f031146fd392e33782f7c54b12ab6e93d Mon Sep 17 00:00:00 2001 From: lm Date: Thu, 3 Apr 2014 11:24:44 +0800 Subject: [PATCH] [Jenkins][ci skip]: Monitor jenkins queue build --- tools/jenkins-scripts/job-trigger.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/jenkins-scripts/job-trigger.py b/tools/jenkins-scripts/job-trigger.py index 0f54d951e1..6b15fe9836 100755 --- a/tools/jenkins-scripts/job-trigger.py +++ b/tools/jenkins-scripts/job-trigger.py @@ -6,6 +6,21 @@ import os import requests import sys 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(): #get payload from os env @@ -40,6 +55,7 @@ def main(): target_url = os.environ['JOB_PULL_REQUEST_BUILD_URL'] if(action == 'closed'): + check_queue_build(action, pr_num, statuses_url) print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered' return(0) @@ -63,6 +79,7 @@ def main(): except: traceback.print_exc() + check_queue_build(action, pr_num, statuses_url) job_trigger_url = os.environ['JOB_TRIGGER_URL'] #send trigger and payload post_data = {'payload':""}