mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5176 from heliclei/develop
[Jenkins]fix jenkins api, get correct build result
This commit is contained in:
commit
9bb3444e04
|
@ -3,26 +3,30 @@ import json
|
|||
import requests
|
||||
import jenkinsapi
|
||||
from jenkinsapi.jenkins import Jenkins
|
||||
from jenkinsapi.constants import STATUS_SUCCESS
|
||||
|
||||
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']
|
||||
url = pr['html_url']
|
||||
print "build pr:" + url
|
||||
#get statuses url
|
||||
statuses_url = pr['statuses_url']
|
||||
print statuses_url
|
||||
|
||||
J = Jenkins(os.environ['JENKINS_URL'])
|
||||
target_url = os.environ['BUILD_URL']
|
||||
build_number = int(os.environ['BUILD_NUMBER'])
|
||||
data = {"state":"pending", "target_url":target_url}
|
||||
access_token = os.environ['GITHUB_ACCESS_TOKEN']
|
||||
Headers = {"Authorization":"token " + access_token}
|
||||
|
||||
result = J[os.environ['JOB_NAME']].get_build(build_number).get_status()
|
||||
|
||||
if(J[os.environ['JOB_NAME']].get_last_build().is_good()):
|
||||
if(result == STATUS_SUCCESS):
|
||||
data['state'] = "success"
|
||||
else:
|
||||
data['state'] = "failure"
|
||||
data['state'] = "failure"
|
||||
|
||||
requests.post(statuses_url, data=json.dumps(data), headers=Headers)
|
||||
|
|
Loading…
Reference in New Issue