Add config options --jobs-only and --views-only
Add options --jobs-only and --views-only to job_builder section in config file. By default JJB updates both jobs and views. Some cases non-admin users are not allowed to update views on Jenkins which requires explicity using -j flag. Allow users to set a config option 'update=jobs|views|all' in the 'job_builder' section implicitly use --jobs-only or --views-only and control these flags from the config file. Note: CLI options takes precedence over the config file. Change-Id: I2a94e5a2d671ccbfc505de2f19b578ecfef9e9d7 Co-Authored-By: Thanh Ha <zxiiro@linux.com> Signed-off-by: Anil Belur <askb23@gmail.com> Signed-off-by: Thanh Ha <zxiiro@linux.com> Signed-off-by: Anil Belur <askb23@gmail.com>
This commit is contained in:
@@ -86,11 +86,17 @@ class JenkinsJobs(object):
|
||||
|
||||
self._set_config(self.jjb_config.builder, 'ignore_cache')
|
||||
self._set_config(self.jjb_config.builder, 'flush_cache')
|
||||
self._set_config(self.jjb_config.builder, 'update')
|
||||
self._set_config(self.jjb_config.yamlparser, 'allow_empty_variables')
|
||||
self._set_config(self.jjb_config.jenkins, 'section')
|
||||
self._set_config(self.jjb_config.jenkins, 'user')
|
||||
self._set_config(self.jjb_config.jenkins, 'password')
|
||||
|
||||
# Note: CLI options override config file options.
|
||||
if getattr(self.options, 'update', None) is None:
|
||||
self.options.update = str(self.jjb_config.builder.get('update',
|
||||
'all'))
|
||||
|
||||
if getattr(self.options, 'plugins_info_path', None) is not None:
|
||||
with io.open(self.options.plugins_info_path, 'r',
|
||||
encoding='utf-8') as yaml_file:
|
||||
|
||||
@@ -72,25 +72,26 @@ class UpdateSubCommand(base.BaseSubCommand):
|
||||
dest='n_workers',
|
||||
help="number of workers to use, 0 for autodetection and 1 "
|
||||
"for just one worker.")
|
||||
update.add_argument(
|
||||
'-j', '--jobs-only',
|
||||
action='store_true', dest='add_jobs',
|
||||
default=False,
|
||||
help='update only jobs'
|
||||
)
|
||||
update.add_argument(
|
||||
'-v', '--views-only',
|
||||
action='store_true', dest='add_views',
|
||||
default=False,
|
||||
help='update only views'
|
||||
)
|
||||
update.add_argument(
|
||||
'--existing-only',
|
||||
action='store_true',
|
||||
default=False,
|
||||
dest='existing_only',
|
||||
help='update existing jobs only'
|
||||
)
|
||||
help='update existing jobs only')
|
||||
|
||||
update_type = update.add_mutually_exclusive_group()
|
||||
update_type.add_argument(
|
||||
'-j', '--jobs-only',
|
||||
action='store_const',
|
||||
dest='update',
|
||||
const='jobs',
|
||||
help='update only jobs')
|
||||
update_type.add_argument(
|
||||
'-v', '--views-only',
|
||||
action='store_const',
|
||||
dest='update',
|
||||
const='views',
|
||||
help='update only views')
|
||||
|
||||
def _generate_xmljobs(self, options, jjb_config=None):
|
||||
builder = JenkinsManager(jjb_config)
|
||||
@@ -122,11 +123,6 @@ class UpdateSubCommand(base.BaseSubCommand):
|
||||
return builder, xml_jobs, xml_views
|
||||
|
||||
def execute(self, options, jjb_config):
|
||||
|
||||
if options.add_jobs and options.add_views:
|
||||
raise JenkinsJobsException(
|
||||
'"--views-only" and "--jobs-only" cannot be used together.')
|
||||
|
||||
if options.n_workers < 0:
|
||||
raise JenkinsJobsException(
|
||||
'Number of workers must be equal or greater than 0')
|
||||
@@ -134,12 +130,12 @@ class UpdateSubCommand(base.BaseSubCommand):
|
||||
builder, xml_jobs, xml_views = self._generate_xmljobs(
|
||||
options, jjb_config)
|
||||
|
||||
if options.add_jobs:
|
||||
if options.update == 'jobs':
|
||||
jobs, num_updated_jobs = builder.update_jobs(
|
||||
xml_jobs, n_workers=options.n_workers,
|
||||
existing_only=options.existing_only)
|
||||
logger.info("Number of jobs updated: %d", num_updated_jobs)
|
||||
elif options.add_views:
|
||||
elif options.update == 'views':
|
||||
views, num_updated_views = builder.update_views(
|
||||
xml_views, n_workers=options.n_workers,
|
||||
existing_only=options.existing_only)
|
||||
|
||||
Reference in New Issue
Block a user