oss-fuzz/infra/gcb/wait_for_build.py

69 lines
1.5 KiB
Python
Raw Normal View History

2017-03-11 01:37:19 +00:00
#!/usr/bin/python2
"""Waits for project build on Google Cloud Builder.
Usage: wait_for_build.py <build_id>
"""
import argparse
2017-03-11 01:37:19 +00:00
import sys
import time
import datetime
2017-03-11 01:37:19 +00:00
from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials
POLL_INTERVAL = 15
cloudbuild = None
2017-03-11 01:37:19 +00:00
def get_build(build_id, cloudbuild, project):
return cloudbuild.projects().builds().get(
projectId=project, id=build_id).execute()
2017-03-11 01:37:19 +00:00
def wait_for_build(build_id, project):
DONE_STATUSES = [
'SUCCESS',
'FAILURE',
'INTERNAL_ERROR',
'CANCELLED',
2017-07-19 15:56:18 +00:00
'TIMEOUT',
]
2017-03-11 01:37:19 +00:00
status = None
2017-03-11 01:37:19 +00:00
while True:
build_info = get_build(build_id, cloudbuild, project)
2017-03-14 00:12:20 +00:00
current_status = build_info['status']
if current_status != status:
2018-07-27 03:32:09 +00:00
print datetime.datetime.now(), current_status
sys.stdout.flush()
status = current_status
if status in DONE_STATUSES:
return status == 'SUCCESS'
2017-03-11 01:37:19 +00:00
time.sleep(POLL_INTERVAL)
def main():
global cloudbuild
parser = argparse.ArgumentParser(description='Wait for build to complete')
parser.add_argument(
2018-07-27 03:32:09 +00:00
'-p', '--project', help='Cloud Project', default='oss-fuzz')
parser.add_argument('build_id', help='The Container Builder build ID.')
args = parser.parse_args()
2017-03-11 01:37:19 +00:00
credentials = GoogleCredentials.get_application_default()
cloudbuild = build('cloudbuild', 'v1', credentials=credentials)
2017-03-11 01:37:19 +00:00
success = wait_for_build(args.build_id, args.project)
2017-03-11 01:37:19 +00:00
if not success:
2017-03-11 01:37:19 +00:00
sys.exit(1)
if __name__ == '__main__':
2017-03-11 01:37:19 +00:00
main()