11
11
from optparse import OptionParser
12
12
from datetime import datetime
13
13
14
- __version__ = '2.60 .0'
14
+ __version__ = '2.61 .0'
15
15
16
16
FORMAT = "%(message)s"
17
17
logging .basicConfig (format = FORMAT )
@@ -417,7 +417,7 @@ def upload_test_file(self, project_id, filename):
417
417
"""
418
418
def delete_project_parameters (self , project_id , parameter_id ):
419
419
me = self .get_me ()
420
- path = "/ users/%s/projects/%s/config/parameters/%s" % ( me ['id' ], project_id , parameter_id )
420
+ path = "users/%s/projects/%s/config/parameters/%s" % ( me ['id' ], project_id , parameter_id )
421
421
return self .delete (path = path )
422
422
423
423
""" Get project parameters
@@ -438,7 +438,7 @@ def upload_data_file(self, project_id, filename):
438
438
def set_project_parameters (self , project_id , parameters ):
439
439
#set key value pair for project. e.g. : {'key' : 'my_key', 'value':'my_value'}
440
440
me = self .get_me ()
441
- path = "/ users/%s/projects/%s/config/parameters" % ( me ['id' ], project_id )
441
+ path = "users/%s/projects/%s/config/parameters" % ( me ['id' ], project_id )
442
442
return self .post (path = path , payload = parameters )
443
443
444
444
""" Get project config
@@ -455,7 +455,7 @@ def set_project_config(self, project_id, payload):
455
455
if isinstance (payload , str ):
456
456
payload = json .loads (payload )
457
457
me = self .get_me ()
458
- path = "/ users/%s/projects/%s/config" % ( me ['id' ], project_id )
458
+ path = "users/%s/projects/%s/config" % ( me ['id' ], project_id )
459
459
return self .post (path = path , payload = payload )
460
460
461
461
"""Set project framework based on a framework integer id
@@ -514,7 +514,7 @@ def start_test_run(self, project_id, device_group_id=None, device_model_ids=None
514
514
515
515
# actually start the test run
516
516
me = self .get_me ()
517
- path = "/ users/%s/projects/%s/runs" % (me ['id' ], project_id )
517
+ path = "users/%s/projects/%s/runs" % (me ['id' ], project_id )
518
518
test_run = self .post (path = path , payload = payload )
519
519
print ("Test run id: %s" % test_run ['id' ])
520
520
print ("Name: %s" % test_run ['displayName' ])
@@ -676,8 +676,6 @@ def get_jobs(self, limit=0):
676
676
"""
677
677
def create_job (self , job_name , content , job_type = "BUILD" ):
678
678
job = self .post (path = "me/jobs" , payload = {"name" : job_name , "content" : content , "type" : job_type })
679
- print (job )
680
-
681
679
logger .info ("Job %s: %s (%s) created" % (job ['id' ], job ['name' ], job ['type' ] ))
682
680
return job
683
681
@@ -747,6 +745,34 @@ def download_build_output_files(self, job_id, build_id, results_folder="results"
747
745
logger .info ("No files to download" )
748
746
logger .info ("" )
749
747
748
+ """ Awaits completion of the given test run
749
+ """
750
+ def wait_build (self , job_id , build_id ):
751
+ if job_id and build_id :
752
+ print ("Awaiting completion of build with id {}. Will wait forever polling every {}." .format (
753
+ build_id ,
754
+ '{} minutes' .format (self .polling_interval_mins ) if self .polling_interval_mins != 1 else 'minute' ))
755
+
756
+ while True :
757
+ time .sleep (self .polling_interval_mins * 6 )
758
+ if not self .api_key :
759
+ self .access_token = None
760
+ self .get_token ()
761
+ buildStatus = self .get_build (job_id , build_id )
762
+ if buildStatus and 'state' in buildStatus :
763
+ if buildStatus ['state' ] == "FINISHED" :
764
+ print ("The build with id: %s has FINISHED with status: %s" % (build_id , buildStatus ['status' ]))
765
+ break
766
+ elif buildStatus ['state' ] == "CREATED" :
767
+ print ("[%s] The build with id: %s is awaiting to be scheduled" % (time .strftime ("%H:%M:%S" ), build_id ))
768
+ continue
769
+ elif buildStatus ['state' ] == "BUILDING" :
770
+ print ("[%s] The build with id: %s is running" % (time .strftime ("%H:%M:%S" ), build_id ))
771
+ continue
772
+
773
+ print ("Couldn't establish the state of the build with id: %s. Aborting" % build_id )
774
+ print (buildStatus )
775
+ sys .exit (1 )
750
776
751
777
""" Downloads test run files to a directory hierarchy
752
778
"""
@@ -879,6 +905,18 @@ def format_epilog(self, formatter):
879
905
Download test run screenshots. Screenshots will be downloaded to
880
906
current directory in a structure:
881
907
[test-run-id]/[device-run-id]-[device-name]/screenshots/...
908
+ jobs Get list of your jobs
909
+ builds <job-id> Get list of your builds
910
+ create-job <job-name> <job-configuration> Create a new job. Job configuration in Jenkins pipeline format
911
+ See the sample of Jenkisfile in http://docs.bitbar.com/build-service/guide.html
912
+ update-job <job-id> <job-name> <job-configuration>
913
+ Update existing job
914
+ create-build <job-id> <build-configuration> Create a new build job. See https://cloud.testdroid.com/cloud/swagger-ui.html
915
+ for details of build configuration
916
+ delete-job <job-id> Delete job and all the builds in it
917
+ delete-build <job-id> <build-id> Delete build by id
918
+ download-builds-files <job-id> <build-id> Download all the results of the specific build
919
+ wait-build <job-id> <build-id> Await completion (polling) of the build
882
920
883
921
"""
884
922
parser = MyParser (usage = usage , description = description , epilog = epilog , version = "%s %s" % ("%prog" , __version__ ))
@@ -929,7 +967,8 @@ def get_commands(self):
929
967
"create-build" : self .create_build ,
930
968
"delete-job" : self .delete_job ,
931
969
"delete-build" : self .delete_build ,
932
- "download-builds-files" : self .download_build_output_files
970
+ "download-builds-files" : self .download_build_output_files ,
971
+ "wait-build" : self .wait_build
933
972
934
973
}
935
974
return commands
0 commit comments