Implement a flag and function for starting a job build.

This commit is contained in:
parazyd 2018-09-26 19:17:29 +02:00
parent d9d1ff8dfe
commit cff9839d83
No known key found for this signature in database
GPG Key ID: F0CB28FCF78637DE
2 changed files with 21 additions and 3 deletions

View File

@ -28,7 +28,7 @@ Usage
-----
```
usage: sync_jobs.py [-h] [-a] [-d] [-n] jobname
usage: sync_jobs.py [-h] [-a] [-d] [-n] [-r] jobname
positional arguments:
jobname
@ -38,6 +38,7 @@ optional arguments:
-a, --add
-d, --delete
-n, --dryrun
-r, --run
```
The `jobname` argument should be in a specific format. It should contain
@ -64,5 +65,5 @@ would look something like the following:
sync_jobs.py -a parazyd@dyne.org-vm_amd64-1537977964
```
In case of removing an existing job, all of the above applies the same
way. You just have to use `-d` instead of `-a`.
In case of removing or building an existing job, all of the above applies the
same way. You just have to use `-d` or `-r` instead of `-a`, respectively.

View File

@ -68,6 +68,16 @@ def del_job(jobname):
return run(jarargs)
def run_job(jobname):
"""
Function for running a Jenkins job.
"""
jarargs.append('build')
jarargs.append(jobname.replace('@', 'AT'))
return run(jarargs)
def main():
"""
Main routine.
@ -76,6 +86,7 @@ def main():
parser.add_argument('-a', '--add', action='store_true')
parser.add_argument('-d', '--delete', action='store_true')
parser.add_argument('-n', '--dryrun', action='store_true')
parser.add_argument('-r', '--run', action='store_true')
parser.add_argument('jobname')
# NOTE: jobname should be email-arch-date, and a predefined directory
# somewhere on the filesystem. e.g.:
@ -96,6 +107,12 @@ def main():
return
print('Removing job:', args.jobname)
del_job(args.jobname)
elif args.run:
if args.dryrun:
print('Would build:', args.jobname)
return
print('Building job:', args.jobname)
run_job(args.jobname)
if __name__ == '__main__':