travis_jenkins.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import jenkins
00004 import urllib
00005 import urllib2
00006 import json
00007 import time
00008 
00009 from os import environ as env
00010 
00011 print "TRAVIS_BRANCH",  env['TRAVIS_BRANCH']
00012 print "TRAVIS_BUILD_DIR",env['TRAVIS_BUILD_DIR']
00013 print "TRAVIS_BUILD_ID",env['TRAVIS_BUILD_ID']
00014 print "TRAVIS_BUILD_NUMBER",env['TRAVIS_BUILD_NUMBER']
00015 print "TRAVIS_COMMIT",env['TRAVIS_COMMIT']
00016 print "TRAVIS_COMMIT_RANGE",env['TRAVIS_COMMIT_RANGE']
00017 print "TRAVIS_JOB_ID",env['TRAVIS_JOB_ID']
00018 print "TRAVIS_JOB_NUMBER",env['TRAVIS_JOB_NUMBER']
00019 print "TRAVIS_PULL_REQUEST",env['TRAVIS_PULL_REQUEST']
00020 print "TRAVIS_SECURE_ENV_VARS",env['TRAVIS_SECURE_ENV_VARS']
00021 print "TRAVIS_REPO_SLUG",env['TRAVIS_REPO_SLUG']
00022 
00023 #u = urllib2.Request(j.build_job_url('trusty-travis') , "TRAVIS_BRANCH=%s&TRAVIS_COMMIT=%s&TRAVIS_REPO_SLUG=%s"%(env['TRAVIS_BRANCH'],env['TRAVIS_COMMIT'],env['TRAVIS_REPO_SLUG']))
00024 #print "TRAVIS_BRANCH=%s&TRAVIS_COMMIT=%s&TRAVIS_REPO_SLUG=%s&ROS_DISTRO=%s&ROSWS=%s&BUILDER=%s&USE_DEB=%s"%(env['TRAVIS_BRANCH'],env['TRAVIS_COMMIT'],env['TRAVIS_REPO_SLUG'],env['ROS_DISTRO'],env['ROSWS'],env['BUILDER'],env['USE_DEB'])
00025 #u = j.jenkins_open(urllib2.Request('http://jenkins.jsk.imi.i.u-tokyo.ac.jp:8080/job/trusty-travis/buildWithParameters',"TRAVIS_BRANCH=%s&TRAVIS_COMMIT=%s&TRAVIS_REPO_SLUG=%s&ROS_DISTRO=%s&ROSWS=%s&BUILDER=%s&USE_DEB=%s"%(env['TRAVIS_BRANCH'],env['TRAVIS_COMMIT'],env['TRAVIS_REPO_SLUG'],env['ROS_DISTRO'],env['ROSWS'],env['BUILDER'],env['USE_DEB'])))
00026 #print u
00027 
00028 # this over rides existing methods
00029 BUILD_INFO = 'job/%(name)s/%(number)d/api/json?depth=0'
00030 class Jenkins2(jenkins.Jenkins):
00031 
00032     def build_job(self, name, parameters=None, token=None):
00033         if not self.job_exists(name):
00034             raise jenkins.JenkinsException('no such job[%s]'%(name))
00035         if token:
00036             parameters['token'] = token
00037         print self.build_job_url(name), urllib.urlencode(parameters)
00038         return self.jenkins_open(urllib2.Request(self.build_job_url(name, {'foo':'bar'}), urllib.urlencode(parameters)))
00039 
00040     def get_build_info(self, name, number):
00041         '''
00042         Get build information dictionary.
00043 
00044         :param name: Job name, ``str``
00045         :param name: Build number, ``int``
00046         :returns: dictionary of build information, ``dict``
00047 
00048         Example::
00049 
00050             >>> next_build_number = j.get_job_info('build_name')['next_build_number']
00051             >>> output = j.build_job('build_'+kwargs['vcs_server_type'], params)
00052             >>> sleep(10)
00053             >>> build_info = j.get_build_info('build_name', next_build_number)
00054             >>> print(build_info)
00055             {u'building': False, u'changeSet': {u'items': [{u'date': u'2011-12-19T18:01:52.540557Z', u'msg': u'test', u'revision': 66, u'user': u'unknown', u'paths': [{u'editType': u'edit', u'file': u'/branches/demo/index.html'}]}], u'kind': u'svn', u'revisions': [{u'module': u'http://eaas-svn01.i3.level3.com/eaas', u'revision': 66}]}, u'builtOn': u'', u'description': None, u'artifacts': [{u'relativePath': u'dist/eaas-87-2011-12-19_18-01-57.war', u'displayPath': u'eaas-87-2011-12-19_18-01-57.war', u'fileName': u'eaas-87-2011-12-19_18-01-57.war'}, {u'relativePath': u'dist/eaas-87-2011-12-19_18-01-57.war.zip', u'displayPath': u'eaas-87-2011-12-19_18-01-57.war.zip', u'fileName': u'eaas-87-2011-12-19_18-01-57.war.zip'}], u'timestamp': 1324317717000, u'number': 87, u'actions': [{u'parameters': [{u'name': u'SERVICE_NAME', u'value': u'eaas'}, {u'name': u'PROJECT_NAME', u'value': u'demo'}]}, {u'causes': [{u'userName': u'anonymous', u'shortDescription': u'Started by user anonymous'}]}, {}, {}, {}], u'id': u'2011-12-19_18-01-57', u'keepLog': False, u'url': u'http://eaas-jenkins01.i3.level3.com:9080/job/build_war/87/', u'culprits': [{u'absoluteUrl': u'http://eaas-jenkins01.i3.level3.com:9080/user/unknown', u'fullName': u'unknown'}], u'result': u'SUCCESS', u'duration': 8826, u'fullDisplayName': u'build_war #87'}
00056         '''
00057         try:
00058             response = self.jenkins_open(urllib2.Request(
00059                 self.server + BUILD_INFO % locals()))
00060             if response:
00061                 return json.loads(response)
00062             else:
00063                 raise jenkins.JenkinsException('job[%s] number[%d] does not exist'
00064                                        % (name, number))
00065         except urllib2.HTTPError:
00066             raise jenkins.JenkinsException('job[%s] number[%d] does not exist'
00067                                    % (name, number))
00068         except ValueError:
00069             raise jenkins.JenkinsException(
00070                 'Could not parse JSON info for job[%s] number[%d]'
00071                 % (name, number)
00072             )
00073 
00074 ## start from here
00075 j = Jenkins2('http://jenkins.jsk.imi.i.u-tokyo.ac.jp:8080/')
00076 next_build_number = j.get_job_info('trusty-travis')['nextBuildNumber']
00077 j.build_job('trusty-travis', {'TRAVIS_BRANCH': env['TRAVIS_BRANCH'], 'TRAVIS_COMMIT': env['TRAVIS_COMMIT'], 'TRAVIS_REPO_SLUG': env['TRAVIS_REPO_SLUG'], 'ROS_DISTRO': env['ROS_DISTRO'], 'ROSWS': env['ROSWS'], 'BUILDER': env['BUILDER'], 'USE_DEB':env['USE_DEB']})
00078 
00079 building = True
00080 while building == True :
00081     time.sleep(10)
00082     info = j.get_build_info('trusty-travis',next_build_number)
00083     building = info['building']
00084     result = info['result']
00085     print info['url'], "building..",building, "result...",result
00086 
00087 if result == "SUCCESS" :
00088     exit(0)
00089 else:
00090     exit(1)
00091 
00092 


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Fri Aug 28 2015 11:53:39