axmol/tools/jenkins-scripts/create-job.py

32 lines
788 B
Python
Raw Normal View History

2014-01-06 20:58:00 +08:00
#create ghprb job by pr number
import os
import sys
import json
import requests
#get pr number from cmd
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
r = requests.get(api_get_pr)
pr = r.json()
#forge a payload
2014-01-09 10:56:33 +08:00
payload = {"action":"opened","number":"","pull_request":""}
2014-01-06 20:58:00 +08:00
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
#send trigger and payload
2014-01-06 22:24:47 +08:00
post_data = {'payload':""}
post_data['payload']=json.dumps(payload)
2014-01-06 20:58:00 +08:00
requests.post(jenkins_trigger_url, data=post_data)