blob: 88c718ea3b40ab71840cee160ae4918463645963 [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)')
45 args = parser.parse_args()
46
47 data = {'ZUUL_PIPELINE': args.pipeline,
48 'ZUUL_PROJECT': args.project,
49 'ZUUL_UUID': str(uuid4().hex),
50 'ZUUL_REF': args.refname,
51 'ZUUL_REFNAME': args.refname,
52 'ZUUL_OLDREV': args.oldrev,
53 'ZUUL_NEWREV': args.newrev,
54 'ZUUL_SHORT_OLDREV': args.oldrev[:7],
55 'ZUUL_SHORT_NEWREV': args.newrev[:7],
56 'ZUUL_COMMIT': args.newrev,
57 }
58
59 c.addServer('127.0.0.1', 4730)
60 c.waitForServer()
61
62 job = gear.Job("build:%s" % args.job,
63 json.dumps(data),
64 unique=data['ZUUL_UUID'])
65 c.submitJob(job)
66
67 while not job.complete:
68 time.sleep(1)
69
70if __name__ == '__main__':
71 main()