mirror of https://github.com/google/oss-fuzz.git
* [infra] Add build retry logic inside wait_for_build.py (#419). * typo * address comments by Oliver
This commit is contained in:
parent
302cf1550b
commit
e3bb988d8a
|
@ -16,9 +16,17 @@ POLL_INTERVAL = 15
|
||||||
cloudbuild = None
|
cloudbuild = None
|
||||||
|
|
||||||
|
|
||||||
|
def _print(msg):
|
||||||
|
# Print helper writing to stdout and instantly flushing it to ensure the
|
||||||
|
# output is visible in Jenkins console viewer as soon as possible.
|
||||||
|
sys.stdout.write(msg)
|
||||||
|
sys.stdout.write('\n')
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
def get_build(build_id, cloudbuild, project):
|
def get_build(build_id, cloudbuild, project):
|
||||||
return cloudbuild.projects().builds().get(
|
return cloudbuild.projects().builds().get(projectId=project,
|
||||||
projectId=project, id=build_id).execute()
|
id=build_id).execute()
|
||||||
|
|
||||||
|
|
||||||
def wait_for_build(build_id, project):
|
def wait_for_build(build_id, project):
|
||||||
|
@ -36,8 +44,7 @@ def wait_for_build(build_id, project):
|
||||||
|
|
||||||
current_status = build_info['status']
|
current_status = build_info['status']
|
||||||
if current_status != status:
|
if current_status != status:
|
||||||
print datetime.datetime.now(), current_status
|
_print('%s %s' % (str(datetime.datetime.now()), current_status))
|
||||||
sys.stdout.flush()
|
|
||||||
status = current_status
|
status = current_status
|
||||||
if status in DONE_STATUSES:
|
if status in DONE_STATUSES:
|
||||||
return status == 'SUCCESS'
|
return status == 'SUCCESS'
|
||||||
|
@ -49,8 +56,10 @@ def main():
|
||||||
global cloudbuild
|
global cloudbuild
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Wait for build to complete')
|
parser = argparse.ArgumentParser(description='Wait for build to complete')
|
||||||
parser.add_argument(
|
parser.add_argument('-p',
|
||||||
'-p', '--project', help='Cloud Project', default='oss-fuzz')
|
'--project',
|
||||||
|
help='Cloud Project',
|
||||||
|
default='oss-fuzz')
|
||||||
parser.add_argument('build_id', help='The Container Builder build ID.')
|
parser.add_argument('build_id', help='The Container Builder build ID.')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -58,9 +67,14 @@ def main():
|
||||||
credentials = GoogleCredentials.get_application_default()
|
credentials = GoogleCredentials.get_application_default()
|
||||||
cloudbuild = build('cloudbuild', 'v1', credentials=credentials)
|
cloudbuild = build('cloudbuild', 'v1', credentials=credentials)
|
||||||
|
|
||||||
success = wait_for_build(args.build_id, args.project)
|
if wait_for_build(args.build_id, args.project):
|
||||||
|
return
|
||||||
|
|
||||||
if not success:
|
_print('The build failed. Retrying the same build one more time.')
|
||||||
|
retry_info = cloudbuild.projects().builds().retry(projectId=args.project,
|
||||||
|
id=args.build_id).execute()
|
||||||
|
new_build_id = retry_info['metadata']['build']['id']
|
||||||
|
if not wait_for_build(new_build_id, args.project):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue