Index: buildbucket.py |
diff --git a/buildbucket.py b/buildbucket.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..8e1c2b73d79e4a8a12e010abc438d194f4b4a3e2 |
--- /dev/null |
+++ b/buildbucket.py |
@@ -0,0 +1,95 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Tool for scheduling builds on Buildbucket. |
sheyang
2015/06/08 22:02:13
I guess there'll be a follow-up CL to make "git cl
smut
2015/06/08 22:16:46
Potentially.
|
+ |
+Usage: |
+ $ depot-tools-auth login https://cr-buildbucket.appspot.com |
+ $ buildbucket.py \ |
+ --builder my-builder \ |
+ --bucket master.chromium.tryserver.linux \ |
sheyang
2015/06/08 22:02:13
master.tryserver.chromium.linux
smut
2015/06/08 22:16:46
Done.
|
+ |
+ Schedules a build on buildbucket for my-builder on chromium.tryserver.linux. |
+""" |
+ |
+import argparse |
+import json |
+import urlparse |
+import os |
+import sys |
+ |
+from third_party import httplib2 |
+ |
+import auth |
+ |
+ |
+BUILDBUCKET_URL = 'https://cr-buildbucket.appspot.com' |
+PUT_BUILD_URL = urlparse.urljoin( |
+ BUILDBUCKET_URL, |
+ '_ah/api/buildbucket/v1/builds', |
+) |
+ |
+ |
+def main(argv): |
+ parser = argparse.ArgumentParser() |
nodir
2015/06/08 21:46:15
Please make it
buildbucket put --bucket .....
in
smut
2015/06/08 22:16:47
Done.
|
+ parser.add_argument( |
+ '-m', |
sheyang
2015/06/08 22:02:13
The combination ('-m' and '--bucket') seems strang
smut
2015/06/08 22:16:46
-m for master because -b was taken. added --master
|
+ '--bucket', |
+ help='The bucket to schedule the build on. Typically the master name.', |
sheyang
2015/06/08 22:02:13
I would give an example such as 'master.tryserver.
smut
2015/06/08 22:16:47
Done.
|
+ required=True, |
+ ) |
+ parser.add_argument( |
+ '-b', |
+ '--builder-name', |
+ help='The builder to schedule the build on.', |
+ required=True, |
+ ) |
+ parser.add_argument( |
+ '-p', |
+ '--properties', |
+ help='A file to load a JSON dict of properties from.', |
+ ) |
+ parser.add_argument( |
+ '-v', |
+ '--verbose', |
+ action='store_true', |
+ ) |
+ args = parser.parse_args() |
+ |
+ properties = { |
+ 'category': os.path.basename(argv[0]), |
+ 'reason': os.path.basename(argv[0]), |
nodir
2015/06/08 21:46:15
"buildbucket.py" is not a good category or reason.
smut
2015/06/08 22:16:46
I've seen "CQ" as the category and reason, so I th
|
+ } |
+ if args.properties: |
+ with open(args.properties) as fp: |
+ properties.update(json.load(fp)) |
nodir
2015/06/08 21:46:15
Add exception handling with meaningful explanation
smut
2015/06/08 22:16:46
Exception is pretty clear:
ValueError: No JSON obj
|
+ |
+ authenticator = auth.get_authenticator_for_host( |
+ BUILDBUCKET_URL, |
+ auth.make_auth_config(use_oauth2=True), |
+ ) |
+ http = authenticator.authorize(httplib2.Http()) |
+ http.force_exception_to_status_code = True |
+ response, content = http.request( |
+ PUT_BUILD_URL, |
+ 'PUT', |
+ body=json.dumps({ |
+ 'bucket': args.bucket, |
+ 'parameters_json': json.dumps({ |
+ 'builder_name': args.builder_name, |
+ 'properties': properties, |
+ }), |
+ }), |
+ headers={'Content-Type': 'application/json'}, |
+ ) |
+ |
+ if args.verbose: |
+ print content |
+ |
+ return response.status != 200 |
nodir
2015/06/08 21:46:15
It should return an int, not boolean, no?
smut
2015/06/08 22:16:46
Doesn't really matter. int(False) is 0, int(True)
|
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main(sys.argv)) |