update can now takes several job names

Just like `delete` can accept several jobs names as argument, this patch
let us do the same with `update`.

* builder.update_jobs now filter the jobs against a list
* renamed 'update' argument 'name' to 'names' to make it clear it
  accepts several job names.

Change-Id: I4bcebd98073ec89e172afbec59b93d14de6620ff
Reviewed-on: https://review.openstack.org/24160
Reviewed-by: Anita Kuno <akuno@lavabit.com>
Reviewed-by: James E. Blair <corvus@inaugust.com>
Approved: James E. Blair <corvus@inaugust.com>
Tested-by: Jenkins
This commit is contained in:
Antoine Musso 2013-03-12 12:15:16 +01:00 committed by Jenkins
parent 94a50bb3d1
commit 4f5cfb178f
3 changed files with 12 additions and 6 deletions
doc/source
jenkins_jobs

@ -72,3 +72,8 @@ you can run that command as often as you like, and it will only update
the configuration in Jenkins if the defined configuration has changed
since the last time it was run. Note: if you modify a job directly in
Jenkins, jenkins-jobs will not know about it and will not update it.
To update a specific list of jobs, simply pass them as additional
arguments after the configuration path. To update Foo1 and Foo2 run::
jenkins-jobs update /path/to/config Foo1 Foo2

@ -313,7 +313,7 @@ class Builder(object):
for job in jobs:
self.delete_job(job['name'])
def update_job(self, fn, name=None, output_dir=None):
def update_job(self, fn, names=None, output_dir=None):
if os.path.isdir(fn):
files_to_process = [os.path.join(fn, f)
for f in os.listdir(fn)
@ -327,11 +327,12 @@ class Builder(object):
parser.generateXML()
parser.jobs.sort(lambda a, b: cmp(a.name, b.name))
for job in parser.jobs:
if name and job.name != name:
if names and job.name not in names:
continue
if output_dir:
if name:
if names:
print job.output()
continue
fn = os.path.join(output_dir, job.name)

@ -21,7 +21,7 @@ def main():
dest='command')
parser_update = subparser.add_parser('update')
parser_update.add_argument('path', help='Path to YAML file or directory')
parser_update.add_argument('name', help='name of job', nargs='?')
parser_update.add_argument('names', help='name(s) of job(s)', nargs='+')
parser_test = subparser.add_parser('test')
parser_test.add_argument('path', help='Path to YAML file or directory')
parser_test.add_argument('-o', dest='output_dir',
@ -82,8 +82,8 @@ def main():
builder.delete_all_jobs()
elif options.command == 'update':
logger.info("Updating jobs in {0} ({1})".format(
options.path, options.name))
builder.update_job(options.path, options.name)
options.path, options.names))
builder.update_job(options.path, options.names)
elif options.command == 'test':
builder.update_job(options.path, options.name,
output_dir=options.output_dir)