mirror of https://github.com/google/oss-fuzz.git
[infra] gcb: Add cancel.py
Also recognize CANCELLED status in wait_for_build.
This commit is contained in:
parent
7df64d4ac4
commit
3a746bab8a
|
@ -0,0 +1,41 @@
|
||||||
|
#!/usr/bin/python2
|
||||||
|
|
||||||
|
"""Cancels project build on Google Cloud Builder.
|
||||||
|
|
||||||
|
Usage: cancel.py <build_id>
|
||||||
|
"""
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import collections
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import urllib
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
from oauth2client.client import GoogleCredentials
|
||||||
|
from oauth2client.service_account import ServiceAccountCredentials
|
||||||
|
from googleapiclient.discovery import build
|
||||||
|
|
||||||
|
def usage():
|
||||||
|
sys.stderr.write(
|
||||||
|
"Usage: " + sys.argv[0] + " <build_id>\n")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
usage()
|
||||||
|
|
||||||
|
build_id = sys.argv[1]
|
||||||
|
|
||||||
|
credentials = GoogleCredentials.get_application_default()
|
||||||
|
cloudbuild = build('cloudbuild', 'v1', credentials=credentials)
|
||||||
|
print cloudbuild.projects().builds().cancel(
|
||||||
|
projectId='clusterfuzz-external', id=build_id, body={}).execute()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -12,7 +12,6 @@ import datetime
|
||||||
from googleapiclient.discovery import build
|
from googleapiclient.discovery import build
|
||||||
from oauth2client.client import GoogleCredentials
|
from oauth2client.client import GoogleCredentials
|
||||||
|
|
||||||
|
|
||||||
POLL_INTERVAL = 15
|
POLL_INTERVAL = 15
|
||||||
cloudbuild = None
|
cloudbuild = None
|
||||||
|
|
||||||
|
@ -29,7 +28,12 @@ def get_build(build_id, cloudbuild):
|
||||||
|
|
||||||
|
|
||||||
def wait_for_build(build_id):
|
def wait_for_build(build_id):
|
||||||
global cloudbuild
|
DONE_STATUSES = [
|
||||||
|
'SUCCESS',
|
||||||
|
'FAILURE',
|
||||||
|
'INTERNAL_ERROR',
|
||||||
|
'CANCELLED',
|
||||||
|
]
|
||||||
|
|
||||||
status = None
|
status = None
|
||||||
while True:
|
while True:
|
||||||
|
@ -40,7 +44,7 @@ def wait_for_build(build_id):
|
||||||
print datetime.datetime.now(), current_status
|
print datetime.datetime.now(), current_status
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
status = current_status
|
status = current_status
|
||||||
if status == 'SUCCESS' or status == 'FAILURE' or status == 'INTERNAL_ERROR':
|
if status in DONE_STATUSES:
|
||||||
return status == 'SUCCESS'
|
return status == 'SUCCESS'
|
||||||
|
|
||||||
time.sleep(POLL_INTERVAL)
|
time.sleep(POLL_INTERVAL)
|
||||||
|
|
Loading…
Reference in New Issue