-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-job.py
executable file
·51 lines (36 loc) · 1.54 KB
/
run-job.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import sys
from argparse import ArgumentParser
from jenkins import Jenkins
from config import get_jobs, DEFAULT_RELEASES
from jenkins_creds import (jenkins_host, jenkins_user, jenkins_pass)
def main():
parser = ArgumentParser()
parser.add_argument('-j', '--jobname', type=str, default=None)
parser.add_argument('-n', '--dry_run', action='store_true')
parser.add_argument('-d', '--distro', type=str, default='all') # maybe implement an 'all' logic?
parser.add_argument('-r', '--release', type=str, default='leste')
args = parser.parse_args()
if args.release not in DEFAULT_RELEASES:
print('Release unsupported. Use something from %s' % DEFAULT_RELEASES.keys())
sys.exit(1)
if args.distro not in DEFAULT_RELEASES[args.release]:
print('Distro unsupported. Use something from %s' % DEFAULT_RELEASES[args.release])
sys.exit(1)
release = args.release
distribution = args.distro
japi = Jenkins(jenkins_host, username=jenkins_user, password=jenkins_pass)
jobs = get_jobs()
if args.dry_run:
print('Would start:', args.jobname)
sys.exit(0)
if args.jobname not in jobs:
print('Job does not exist in config')
sys.exit(1)
# Racy, but whatever
nextjob = japi.get_job_info('%s-source' % args.jobname)['nextBuildNumber']
job_no = japi.build_job('%s-source' % args.jobname,
{'release': release, 'distribution': distribution})
print('Build number:', nextjob)
if __name__ == '__main__':
main()