aboutsummaryrefslogtreecommitdiff
path: root/infra/gcb/cancel.py
blob: 331244fedf9147da9f7ec1c3d0193ec681d995ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/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='oss-fuzz', id=build_id, body={}).execute()


if __name__ == '__main__':
  main()