blob: 9be93a105a0abad62b6e938298e9bf9ca5f937a6 [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)')
Clark Boyland7e8f3a2013-10-03 15:31:04 -070045 parser.add_argument('--logpath', dest='logpath', required=True,
46 help='Path for log files.')
James E. Blair2f143f32013-06-25 12:58:39 -040047 args = parser.parse_args()
48
49 data = {'ZUUL_PIPELINE': args.pipeline,
50 'ZUUL_PROJECT': args.project,
51 'ZUUL_UUID': str(uuid4().hex),
52 'ZUUL_REF': args.refname,
53 'ZUUL_REFNAME': args.refname,
54 'ZUUL_OLDREV': args.oldrev,
55 'ZUUL_NEWREV': args.newrev,
56 'ZUUL_SHORT_OLDREV': args.oldrev[:7],
57 'ZUUL_SHORT_NEWREV': args.newrev[:7],
58 'ZUUL_COMMIT': args.newrev,
Clark Boyland7e8f3a2013-10-03 15:31:04 -070059 'LOG_PATH': args.logpath,
James E. Blair2f143f32013-06-25 12:58:39 -040060 }
61
62 c.addServer('127.0.0.1', 4730)
63 c.waitForServer()
64
65 job = gear.Job("build:%s" % args.job,
66 json.dumps(data),
67 unique=data['ZUUL_UUID'])
68 c.submitJob(job)
69
70 while not job.complete:
71 time.sleep(1)
72
73if __name__ == '__main__':
74 main()