mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5166 from heliclei/develop
[jenkins]add post build script
This commit is contained in:
commit
3829a1aa46
|
@ -9,11 +9,11 @@ import requests
|
||||||
pr_num = sys.argv[1]
|
pr_num = sys.argv[1]
|
||||||
|
|
||||||
#get github access token
|
#get github access token
|
||||||
access_token = os.environ['GITHUB_ACCESS_TOKEN']
|
|
||||||
|
|
||||||
#get pr data via github api
|
#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)
|
r = requests.get(api_get_pr)
|
||||||
pr = r.json()
|
pr = r.json()
|
||||||
|
@ -23,7 +23,7 @@ payload = {"action":"opened","number":"","pull_request":""}
|
||||||
payload['number']=pr_num
|
payload['number']=pr_num
|
||||||
payload['pull_request']=pr
|
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
|
#send trigger and payload
|
||||||
post_data = {'payload':""}
|
post_data = {'payload':""}
|
||||||
|
|
|
@ -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)
|
|
@ -54,7 +54,11 @@ def main():
|
||||||
branch = pr['base']['ref']
|
branch = pr['base']['ref']
|
||||||
|
|
||||||
#set commit status to pending
|
#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)
|
set_description(pr_desc, target_url)
|
||||||
|
|
||||||
|
@ -141,21 +145,13 @@ def main():
|
||||||
|
|
||||||
#get build result
|
#get build result
|
||||||
print "build finished and return " + str(ret)
|
print "build finished and return " + str(ret)
|
||||||
|
|
||||||
exit_code = 1
|
exit_code = 1
|
||||||
if ret == 0:
|
if ret == 0:
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
data['state'] = "success"
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
exit_code = 1
|
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
|
#clean workspace
|
||||||
os.system("cd " + os.environ['WORKSPACE']);
|
os.system("cd " + os.environ['WORKSPACE']);
|
||||||
os.system("git checkout develop")
|
os.system("git checkout develop")
|
||||||
|
|
Loading…
Reference in New Issue