blob: dff4e3fd1dbea2e960c253459e77fd4abf0e37e3 [file] [log] [blame]
James E. Blair2f143f32013-06-25 12:58:39 -04001#!/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
20import argparse
21import time
22import json
23from uuid import uuid4
24
25import gear
26
27
28def 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 Stanley8928ad42014-02-13 20:12:34 +000045 parser.add_argument('--url', dest='url',
46 default='http://zuul.openstack.org/p', help='Zuul URL')
Clark Boyland7e8f3a2013-10-03 15:31:04 -070047 parser.add_argument('--logpath', dest='logpath', required=True,
48 help='Path for log files.')
James E. Blair2f143f32013-06-25 12:58:39 -040049 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 Stanley8928ad42014-02-13 20:12:34 +000061 'ZUUL_URL': args.url,
Clark Boyland7e8f3a2013-10-03 15:31:04 -070062 'LOG_PATH': args.logpath,
James E. Blair2f143f32013-06-25 12:58:39 -040063 }
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'])
71 c.submitJob(job)
72
73 while not job.complete:
74 time.sleep(1)
75
76if __name__ == '__main__':
77 main()