From da3e7d80db468b874d2676c86c7e2220f9096b8e Mon Sep 17 00:00:00 2001 From: heliclei Date: Tue, 5 Aug 2014 16:22:01 +0800 Subject: [PATCH 1/2] [jenkins][ci skip]use github access token to retrive commits --- tools/jenkins-scripts/job-trigger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/jenkins-scripts/job-trigger.py b/tools/jenkins-scripts/job-trigger.py index fbdcf0c3e1..c17f0bc01d 100755 --- a/tools/jenkins-scripts/job-trigger.py +++ b/tools/jenkins-scripts/job-trigger.py @@ -76,7 +76,7 @@ def main(): print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered' return(0) - r = requests.get(pr['url']+"/commits", proxies = proxyDict) + r = requests.get(pr['url']+"/commits", headers=Headers, proxies = proxyDict) commits = r.json() last_commit = commits[len(commits)-1] message = last_commit['commit']['message'] From 5bd0e14b17ce16c0d984d9bf9ea4a7ab8652c95f Mon Sep 17 00:00:00 2001 From: heliclei Date: Tue, 5 Aug 2014 18:01:09 +0800 Subject: [PATCH 2/2] refine code --- tools/jenkins-scripts/job-trigger.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/jenkins-scripts/job-trigger.py b/tools/jenkins-scripts/job-trigger.py index c17f0bc01d..fb979066ca 100755 --- a/tools/jenkins-scripts/job-trigger.py +++ b/tools/jenkins-scripts/job-trigger.py @@ -8,6 +8,9 @@ import sys import traceback from jenkinsapi.jenkins import Jenkins +access_token = os.environ['GITHUB_ACCESS_TOKEN'] +Headers = {"Authorization":"token " + access_token} + http_proxy = '' if(os.environ.has_key('HTTP_PROXY')): http_proxy = os.environ['HTTP_PROXY'] @@ -28,8 +31,6 @@ def check_queue_build(action, pr_num, statuses_url): queues.delete_item(queue) target_url = os.environ['JOB_PULL_REQUEST_BUILD_URL'] data = {"state":"error", "target_url":target_url} - access_token = os.environ['GITHUB_ACCESS_TOKEN'] - Headers = {"Authorization":"token " + access_token} try: requests.post(statuses_url, data=json.dumps(data), headers=Headers, proxies = proxyDict) except: @@ -91,8 +92,7 @@ def main(): return(0) data = {"state":"pending", "target_url":target_url, "context":"Jenkins CI", "description":"Waiting available build machine..."} - access_token = os.environ['GITHUB_ACCESS_TOKEN'] - Headers = {"Authorization":"token " + access_token} + try: requests.post(statuses_url, data=json.dumps(data), headers=Headers, proxies = proxyDict)