Merge pull request #5166 from heliclei/develop

[jenkins]add post build script
This commit is contained in:
James Chen 2014-01-22 18:47:43 -08:00
commit 3829a1aa46
3 changed files with 38 additions and 14 deletions

View File

@ -9,11 +9,11 @@ import requests
pr_num = sys.argv[1]
#get github access token
access_token = os.environ['GITHUB_ACCESS_TOKEN']
#get pr data via github api
api_get_pr = "https://api.github.com/repos/cocos2d/cocos2d-x/pulls/"+str(pr_num)+"?access_token="+access_token
api_get_pr = "https://api.github.com/repos/cocos2d/cocos2d-x/pulls/"+str(pr_num)
r = requests.get(api_get_pr)
pr = r.json()
@ -23,7 +23,7 @@ payload = {"action":"opened","number":"","pull_request":""}
payload['number']=pr_num
payload['pull_request']=pr
jenkins_trigger_url="http://ci.cocos2d-x.org:8000/job/cocos-2dx-pull-request-build/buildWithParameters?token="+access_token
jenkins_trigger_url="http://115.28.134.83:8000/job/cocos-2dx-pull-request-build/buildWithParameters?token=ced2014"
#send trigger and payload
post_data = {'payload':""}

View File

@ -0,0 +1,28 @@
import os
import json
import requests
import jenkinsapi
from jenkinsapi.jenkins import Jenkins
payload_str = os.environ['payload']
payload_str = payload_str.decode('utf-8','ignore')
#parse to json obj
payload = json.loads(payload_str)
pr = payload['pull_request']
#get statuses url
statuses_url = pr['statuses_url']
print statuses_url
J = Jenkins(os.environ['JENKINS_URL'])
target_url = os.environ['BUILD_URL']
data = {"state":"pending", "target_url":target_url}
access_token = os.environ['GITHUB_ACCESS_TOKEN']
Headers = {"Authorization":"token " + access_token}
if(J[os.environ['JOB_NAME']].get_last_build().is_good()):
data['state'] = "success"
else:
data['state'] = "failure"
requests.post(statuses_url, data=json.dumps(data), headers=Headers)

View File

@ -54,7 +54,11 @@ def main():
branch = pr['base']['ref']
#set commit status to pending
target_url = os.environ['BUILD_URL']
#target_url = os.environ['BUILD_URL']
jenkins_url = os.environ['JENKINS_URL']
job_name = os.environ['JOB_NAME'].split('/')[0]
build_number = os.environ['BUILD_NUMBER']
target_url = jenkins_url + 'job/' + job_name + '/' + build_number
set_description(pr_desc, target_url)
@ -141,21 +145,13 @@ def main():
#get build result
print "build finished and return " + str(ret)
exit_code = 1
if ret == 0:
exit_code = 0
data['state'] = "success"
else:
exit_code = 1
data['state'] = "failure"
#set commit status
try:
requests.post(statuses_url, data=json.dumps(data), headers=Headers)
except:
traceback.print_exc()
#clean workspace
os.system("cd " + os.environ['WORKSPACE']);
os.system("git checkout develop")