Add 'delete-all' subcommand to clear all jobs from Jenkins
Change-Id: Ic31b468b6cd1285578038af8f08020e5c4e30c63 Reviewed-on: https://review.openstack.org/13876 Reviewed-by: Clark Boylan <clark.boylan@gmail.com> Approved: James E. Blair <corvus@inaugust.com> Reviewed-by: James E. Blair <corvus@inaugust.com> Tested-by: Jenkins
This commit is contained in:
parent
f05c9a3375
commit
2b1028dc89
15
jenkins-jobs
15
jenkins-jobs
@ -4,6 +4,13 @@ import jenkins_jobs.builder
|
||||
import argparse
|
||||
import ConfigParser
|
||||
import logging
|
||||
import sys
|
||||
|
||||
|
||||
def confirm(question):
|
||||
answer = raw_input('%s (Y/N): ' % question).upper().strip()
|
||||
if not answer == 'Y':
|
||||
sys.exit('Aborted')
|
||||
|
||||
|
||||
def main():
|
||||
@ -20,6 +27,9 @@ def main():
|
||||
parser_test.add_argument('name', help='name of job', nargs='?')
|
||||
parser_delete = subparser.add_parser('delete')
|
||||
parser_delete.add_argument('name', help='name of job', nargs='+')
|
||||
subparser.add_parser('delete-all',
|
||||
help='Delete *ALL* jobs from Jenkins server, including those '
|
||||
'jobs not managed Jenkins Job Builder.')
|
||||
parser.add_argument('--conf', dest='conf', help='Configuration file')
|
||||
parser.add_argument('-l', '--log_level', dest='log_level', default='info',
|
||||
help="Log level (default: %(default)s)")
|
||||
@ -52,6 +62,11 @@ def main():
|
||||
for job in options.name:
|
||||
logger.info("Deleting job {0}".format(job))
|
||||
builder.delete_job(job)
|
||||
elif options.command == 'delete-all':
|
||||
confirm('Sure you want to delete *ALL* jobs from Jenkins server?\n'
|
||||
'(including those not managed by Jenkins Job Builder)')
|
||||
logger.info("Deleting all jobs")
|
||||
builder.delete_all_jobs()
|
||||
elif options.command == 'update':
|
||||
logger.info("Updating jobs in {0} ({1})".format(options.path,
|
||||
options.name))
|
||||
|
@ -241,6 +241,9 @@ class Jenkins(object):
|
||||
if self.is_job(job_name):
|
||||
self.jenkins.delete_job(job_name)
|
||||
|
||||
def get_jobs(self):
|
||||
return self.jenkins.get_jobs()
|
||||
|
||||
|
||||
class Builder(object):
|
||||
def __init__(self, jenkins_url, jenkins_user, jenkins_password,
|
||||
@ -254,6 +257,11 @@ class Builder(object):
|
||||
if(self.cache.is_cached(name)):
|
||||
self.cache.set(name, '')
|
||||
|
||||
def delete_all_jobs(self):
|
||||
jobs = self.jenkins.get_jobs()
|
||||
for job in jobs:
|
||||
self.delete_job(job['name'])
|
||||
|
||||
def update_job(self, fn, name=None, output_dir=None):
|
||||
if os.path.isdir(fn):
|
||||
files_to_process = [os.path.join(fn, f)
|
||||
|
Loading…
x
Reference in New Issue
Block a user