db35627b52
Change-Id: I6899aadddeec6b5e53803d173889890a1e8ebd91 Reviewed-on: https://review.openstack.org/13341 Reviewed-by: Monty Taylor <mordred@inaugust.com> Approved: James E. Blair <corvus@inaugust.com> Reviewed-by: James E. Blair <corvus@inaugust.com> Tested-by: Jenkins
64 lines
2.5 KiB
Python
Executable File
64 lines
2.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import jenkins_jobs.builder
|
|
import argparse
|
|
import ConfigParser
|
|
import logging
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
subparser = parser.add_subparsers(help='update, test or delete job',
|
|
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_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',
|
|
help='Path to output XML')
|
|
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='+')
|
|
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)")
|
|
options = parser.parse_args()
|
|
|
|
options.log_level = getattr(logging, options.log_level.upper(),
|
|
logging.INFO)
|
|
logging.basicConfig(level=options.log_level)
|
|
logger = logging.getLogger()
|
|
|
|
if options.conf:
|
|
conf = options.conf
|
|
else:
|
|
conf = '/etc/jenkins_jobs/jenkins_jobs.ini'
|
|
|
|
if not options.command == 'test':
|
|
logger.debug("Reading config from {0}".format(conf))
|
|
conffp = open(conf, 'r')
|
|
config = ConfigParser.ConfigParser()
|
|
config.readfp(conffp)
|
|
else:
|
|
config = {}
|
|
logger.debug("Config: {0}".format(config))
|
|
builder = jenkins_jobs.builder.Builder(config.get('jenkins', 'url'),
|
|
config.get('jenkins', 'user'),
|
|
config.get('jenkins', 'password'))
|
|
|
|
if options.command == 'delete':
|
|
for job in options.name:
|
|
logger.info("Deleting job {0}".format(job))
|
|
builder.delete_job(job)
|
|
elif options.command == 'update':
|
|
logger.info("Updating jobs in {0} ({1})".format(options.path,
|
|
options.name))
|
|
builder.update_job(options.path, options.name)
|
|
elif options.command == 'test':
|
|
builder.update_job(options.path, options.name,
|
|
output_dir=options.output_dir)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|