James E. Blair | 2f143f3 | 2013-06-25 12:58:39 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2013 OpenStack Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | # This script can be used to manually trigger a job in the same way that |
| 17 | # Zuul does. At the moment, it only supports the post set of Zuul |
| 18 | # parameters. |
| 19 | |
| 20 | import argparse |
| 21 | import time |
| 22 | import json |
| 23 | from uuid import uuid4 |
| 24 | |
| 25 | import gear |
| 26 | |
| 27 | |
| 28 | def main(): |
| 29 | c = gear.Client() |
| 30 | |
| 31 | parser = argparse.ArgumentParser(description='Trigger a Zuul job.') |
| 32 | parser.add_argument('--job', dest='job', required=True, |
| 33 | help='Job Name') |
| 34 | parser.add_argument('--project', dest='project', required=True, |
| 35 | help='Project name') |
| 36 | parser.add_argument('--pipeline', dest='pipeline', default='release', |
| 37 | help='Zuul pipeline') |
| 38 | parser.add_argument('--refname', dest='refname', |
| 39 | help='Ref name') |
| 40 | parser.add_argument('--oldrev', dest='oldrev', |
| 41 | default='0000000000000000000000000000000000000000', |
| 42 | help='Old revision (SHA)') |
| 43 | parser.add_argument('--newrev', dest='newrev', |
| 44 | help='New revision (SHA)') |
Jeremy Stanley | 8928ad4 | 2014-02-13 20:12:34 +0000 | [diff] [blame] | 45 | parser.add_argument('--url', dest='url', |
| 46 | default='http://zuul.openstack.org/p', help='Zuul URL') |
Clark Boylan | d7e8f3a | 2013-10-03 15:31:04 -0700 | [diff] [blame] | 47 | parser.add_argument('--logpath', dest='logpath', required=True, |
| 48 | help='Path for log files.') |
James E. Blair | 2f143f3 | 2013-06-25 12:58:39 -0400 | [diff] [blame] | 49 | args = parser.parse_args() |
| 50 | |
| 51 | data = {'ZUUL_PIPELINE': args.pipeline, |
| 52 | 'ZUUL_PROJECT': args.project, |
| 53 | 'ZUUL_UUID': str(uuid4().hex), |
| 54 | 'ZUUL_REF': args.refname, |
| 55 | 'ZUUL_REFNAME': args.refname, |
| 56 | 'ZUUL_OLDREV': args.oldrev, |
| 57 | 'ZUUL_NEWREV': args.newrev, |
| 58 | 'ZUUL_SHORT_OLDREV': args.oldrev[:7], |
| 59 | 'ZUUL_SHORT_NEWREV': args.newrev[:7], |
| 60 | 'ZUUL_COMMIT': args.newrev, |
Jeremy Stanley | 8928ad4 | 2014-02-13 20:12:34 +0000 | [diff] [blame] | 61 | 'ZUUL_URL': args.url, |
Clark Boylan | d7e8f3a | 2013-10-03 15:31:04 -0700 | [diff] [blame] | 62 | 'LOG_PATH': args.logpath, |
James E. Blair | 2f143f3 | 2013-06-25 12:58:39 -0400 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | c.addServer('127.0.0.1', 4730) |
| 66 | c.waitForServer() |
| 67 | |
| 68 | job = gear.Job("build:%s" % args.job, |
| 69 | json.dumps(data), |
| 70 | unique=data['ZUUL_UUID']) |
James E. Blair | 4b4e28f | 2016-02-04 11:05:32 -0800 | [diff] [blame] | 71 | c.submitJob(job, precedence=gear.PRECEDENCE_HIGH) |
James E. Blair | 2f143f3 | 2013-06-25 12:58:39 -0400 | [diff] [blame] | 72 | |
| 73 | while not job.complete: |
| 74 | time.sleep(1) |
| 75 | |
David Shrewsbury | 699a6b2 | 2017-05-19 09:38:36 -0400 | [diff] [blame] | 76 | |
James E. Blair | 2f143f3 | 2013-06-25 12:58:39 -0400 | [diff] [blame] | 77 | if __name__ == '__main__': |
| 78 | main() |