From d7aa1312bac632a0dc62150a4f09637b2923f72f Mon Sep 17 00:00:00 2001 From: linchaogithub Date: Wed, 12 Mar 2014 15:36:09 +0800 Subject: [PATCH 1/7] [Jenkins] watchdog --- tools/jenkins-scripts/watchdog.py | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tools/jenkins-scripts/watchdog.py diff --git a/tools/jenkins-scripts/watchdog.py b/tools/jenkins-scripts/watchdog.py new file mode 100644 index 0000000000..a54b766496 --- /dev/null +++ b/tools/jenkins-scripts/watchdog.py @@ -0,0 +1,47 @@ +import jenkinsapi +from jenkinsapi.jenkins import Jenkins +import sys +import time +import os + +def main(): + + J = Jenkins('http://115.28.134.83:8000','redmine','cocos2dx2013') + job = J['cocos-2dx-pull-request-build'] + duration = os.environ['duration'] + #Get the numerical ID of the last build. + buildnu = job.get_last_buildnumber() + build = job.get_last_build() + running = build.is_running() + print 'running:',running + + if not running: + return False + print "buildnumber:#",buildnu + nowtime = time.strftime('%M',time.localtime(time.time())) + #print 'nowtime:',nowtime + timeb = build.get_timestamp() + #print 'buildtime:',str(timeb)[14:16] + buildtime = int(str(timeb)[14:16]) + subtime = 0 + if int(nowtime) >= buildtime: + subtime = int(nowtime)-buildtime + else: + subtime = 60-buildtime+int(nowtime) + if subtime > duration: + #print 'subtime',subtime + build.stop() + + return(0) + + +# -------------- main -------------- +if __name__ == '__main__': + sys_ret = 0 + try: + sys_ret = main() + except: + traceback.print_exc() + sys_ret = 1 + finally: + sys.exit(sys_ret) From db68e1feed9ae02bd4b536a04a9b11bd32ed6153 Mon Sep 17 00:00:00 2001 From: linchaogithub Date: Wed, 12 Mar 2014 16:28:23 +0800 Subject: [PATCH 2/7] [jenkins] watchdog --- tools/jenkins-scripts/watchdog.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/jenkins-scripts/watchdog.py b/tools/jenkins-scripts/watchdog.py index a54b766496..30f25ba956 100644 --- a/tools/jenkins-scripts/watchdog.py +++ b/tools/jenkins-scripts/watchdog.py @@ -6,12 +6,14 @@ import os def main(): - J = Jenkins('http://115.28.134.83:8000','redmine','cocos2dx2013') + J = Jenkins('http://115.28.134.83:8000') job = J['cocos-2dx-pull-request-build'] duration = os.environ['duration'] #Get the numerical ID of the last build. buildnu = job.get_last_buildnumber() + #Get the last build build = job.get_last_build() + #Get the build running running = build.is_running() print 'running:',running From d1a84cd7e89c4a23f7e55e99854c720c2816820c Mon Sep 17 00:00:00 2001 From: linchaogithub Date: Wed, 12 Mar 2014 17:18:16 +0800 Subject: [PATCH 3/7] [Jenkins] watchdog --- tools/jenkins-scripts/watchdog.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/jenkins-scripts/watchdog.py b/tools/jenkins-scripts/watchdog.py index 30f25ba956..5aebb128c1 100644 --- a/tools/jenkins-scripts/watchdog.py +++ b/tools/jenkins-scripts/watchdog.py @@ -5,8 +5,9 @@ import time import os def main(): - - J = Jenkins('http://115.28.134.83:8000') + username = os.environ['username'] + password = os.environ['password'] + J = Jenkins('http://115.28.134.83:8000',username,password) job = J['cocos-2dx-pull-request-build'] duration = os.environ['duration'] #Get the numerical ID of the last build. @@ -20,6 +21,7 @@ def main(): if not running: return False print "buildnumber:#",buildnu + #get nowtime nowtime = time.strftime('%M',time.localtime(time.time())) #print 'nowtime:',nowtime timeb = build.get_timestamp() From 9dcca7641ce35bb098044ee3f38057ba6ed8407b Mon Sep 17 00:00:00 2001 From: linchaogithub Date: Thu, 13 Mar 2014 11:16:21 +0800 Subject: [PATCH 4/7] [Jenkins] watchdog --- tools/jenkins-scripts/watchdog.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/tools/jenkins-scripts/watchdog.py b/tools/jenkins-scripts/watchdog.py index 5aebb128c1..fc34237e55 100644 --- a/tools/jenkins-scripts/watchdog.py +++ b/tools/jenkins-scripts/watchdog.py @@ -4,26 +4,24 @@ import sys import time import os -def main(): - username = os.environ['username'] - password = os.environ['password'] - J = Jenkins('http://115.28.134.83:8000',username,password) - job = J['cocos-2dx-pull-request-build'] +#check & kill dead buid +def build_time(_job): + #get build duration duration = os.environ['duration'] - #Get the numerical ID of the last build. - buildnu = job.get_last_buildnumber() - #Get the last build - build = job.get_last_build() - #Get the build running + #Get last build running + build = _job.get_last_build() running = build.is_running() - print 'running:',running - + print 'build_job:',_job,'running:',running if not running: return False + + #Get numerical ID of the last build. + buildnu = _job.get_last_buildnumber() print "buildnumber:#",buildnu #get nowtime nowtime = time.strftime('%M',time.localtime(time.time())) #print 'nowtime:',nowtime + #get build start time timeb = build.get_timestamp() #print 'buildtime:',str(timeb)[14:16] buildtime = int(str(timeb)[14:16]) @@ -34,8 +32,16 @@ def main(): subtime = 60-buildtime+int(nowtime) if subtime > duration: #print 'subtime',subtime + #kill dead buid build.stop() +def main(): + username = os.environ['username'] + password = os.environ['password'] + J = Jenkins('http://115.28.134.83:8000',username,password) + #get all jenkins jobs + for key,job in J.iteritems(): + build_time(job) return(0) @@ -49,3 +55,4 @@ if __name__ == '__main__': sys_ret = 1 finally: sys.exit(sys_ret) + From 347dd55f3dd9be7c86b77f3bed88066083518a9c Mon Sep 17 00:00:00 2001 From: linchaogithub Date: Thu, 13 Mar 2014 14:12:29 +0800 Subject: [PATCH 5/7] [jenkins-job-watchdog-threshold]replace[duration] --- tools/jenkins-scripts/watchdog.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/jenkins-scripts/watchdog.py b/tools/jenkins-scripts/watchdog.py index fc34237e55..feff7a3731 100644 --- a/tools/jenkins-scripts/watchdog.py +++ b/tools/jenkins-scripts/watchdog.py @@ -6,8 +6,8 @@ import os #check & kill dead buid def build_time(_job): - #get build duration - duration = os.environ['duration'] + #get jenkins-job-watchdog-threshold + threshold = os.environ['jenkins-job-watchdog-threshold'] #Get last build running build = _job.get_last_build() running = build.is_running() @@ -30,7 +30,7 @@ def build_time(_job): subtime = int(nowtime)-buildtime else: subtime = 60-buildtime+int(nowtime) - if subtime > duration: + if subtime > threshold: #print 'subtime',subtime #kill dead buid build.stop() From 17ba28de2a6357b3a5ef7551ab78d853729d5811 Mon Sep 17 00:00:00 2001 From: qiaofeng00oo Date: Thu, 13 Mar 2014 16:29:47 +0800 Subject: [PATCH 6/7] add cocos-console-test.py to tools/jenkins-scripts/ --- tools/jenkins-scripts/cocos-console-test.py | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 tools/jenkins-scripts/cocos-console-test.py diff --git a/tools/jenkins-scripts/cocos-console-test.py b/tools/jenkins-scripts/cocos-console-test.py new file mode 100755 index 0000000000..85c90f1229 --- /dev/null +++ b/tools/jenkins-scripts/cocos-console-test.py @@ -0,0 +1,72 @@ +#!/usr/bin/python +#create new project by cocos-console +#build new project and run + +import os +import sys + +project_types = ['cpp', 'lua'] +PROJ_SUFFIX = 'Proj' +phonePlats = ['mac','ios','android'] + +cocos_console_dir = 'tools/cocos2d-console/bin/' + +#now cocos2d-console suport different run on Platforms, e.g: only run android on win +runSupport = { + 'darwin' : [1, 1, 1], + 'win' : [0, 0, 1], + 'linux' : [0, 0, 1] +} + +curPlat = sys.platform +if curPlat.find('linux') >= 0: + curPlat = 'linux' +elif curPlat.find('darwin') >= 0: + curPlat = 'darwin' +else: + curPlat = 'win' +print 'current platform is:', curPlat + +def clean_project(): + for proj in project_types: + cmd = 'rm -rf '+proj+PROJ_SUFFIX + os.system(cmd) + +def create_project(): + print 'will create_project: ' + idx = 0 + for proj in project_types: + print 'proj: ', proj + cmd = './'+cocos_console_dir+'cocos new -l '+proj+' '+proj+PROJ_SUFFIX + print proj,'cmd:',cmd + idx += 1 + info_create = os.system(cmd) #call cmd on win is diff + print 'create project',proj,' is:', not info_create +def build_run(): + print 'will build and run' + for proj in project_types: + idx = 0 + for phone in phonePlats: + cmd = './'+cocos_console_dir+'cocos run -p '+phone+' -s '+proj+PROJ_SUFFIX + print proj,'cmd:',cmd + if runSupport[curPlat][idx]: + info_run = os.system(cmd) + print 'run project', proj, 'is:', not info_run + idx += 1 + +def main(): + clean_project() + create_project() + build_run() + +# -------------- main -------------- +if __name__ == '__main__': + sys_ret = 0 + try: + sys_ret = main() + except: + traceback.print_exc() + sys_ret = 1 + finally: + sys.exit(sys_ret) + From 3013bf2d6dd496d86983a3935927efa849d4ba97 Mon Sep 17 00:00:00 2001 From: qiaofeng00oo Date: Thu, 13 Mar 2014 17:05:10 +0800 Subject: [PATCH 7/7] modify cocos-console-test.py. --- tools/jenkins-scripts/cocos-console-test.py | 25 ++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/jenkins-scripts/cocos-console-test.py b/tools/jenkins-scripts/cocos-console-test.py index 85c90f1229..2c67ab746d 100755 --- a/tools/jenkins-scripts/cocos-console-test.py +++ b/tools/jenkins-scripts/cocos-console-test.py @@ -18,6 +18,19 @@ runSupport = { 'linux' : [0, 0, 1] } +_argvs = sys.argv +print 'input argvs:', _argvs[1], _argvs[2] +_will_create = False +_will_run = False +if _argvs[1]=='create' || _argvs[2]=='create': + _will_create = True +if _argvs[1]=='run' || _argvs[2]=='run': + _will_create = True + _will_run = True +if _will_create == False and _will_run == False: + _will_create = True + _will_run = True + curPlat = sys.platform if curPlat.find('linux') >= 0: curPlat = 'linux' @@ -37,7 +50,7 @@ def create_project(): idx = 0 for proj in project_types: print 'proj: ', proj - cmd = './'+cocos_console_dir+'cocos new -l '+proj+' '+proj+PROJ_SUFFIX + cmd = 'cocos new -l '+proj+' '+proj+PROJ_SUFFIX print proj,'cmd:',cmd idx += 1 info_create = os.system(cmd) #call cmd on win is diff @@ -47,7 +60,7 @@ def build_run(): for proj in project_types: idx = 0 for phone in phonePlats: - cmd = './'+cocos_console_dir+'cocos run -p '+phone+' -s '+proj+PROJ_SUFFIX + cmd = 'cocos run -p '+phone+' -s '+proj+PROJ_SUFFIX print proj,'cmd:',cmd if runSupport[curPlat][idx]: info_run = os.system(cmd) @@ -55,9 +68,11 @@ def build_run(): idx += 1 def main(): - clean_project() - create_project() - build_run() + if _will_create: + clean_project() + create_project() + if _will_run: + build_run() # -------------- main -------------- if __name__ == '__main__':