Added option to print job names as urls

Add print_job_urls = True to [job_builder] to enable output as urls
instead of simple job names when changing them.

Change-Id: I3454606a50ca385c87d8c13d3eab5d30d94cf02f
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
This commit is contained in:
Sorin Sbarnea 2017-05-10 11:49:06 +01:00
parent 92a828de6a
commit b76ed1629d
3 changed files with 24 additions and 2 deletions

View File

@ -52,6 +52,11 @@ job_builder section
string, allowing you to use those strings without having to define all the string, allowing you to use those strings without having to define all the
keys it might be using. keys it might be using.
**print_job_urls**
(Optional) If set to True it will print full jobs urls while updating jobs,
so user can be sure which instance was updated. User may click the link to
go directly to that job. False by default.
jenkins section jenkins section
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^

View File

@ -104,12 +104,22 @@ class JenkinsManager(object):
self._job_list = set(job['fullname'] for job in self.jobs) self._job_list = set(job['fullname'] for job in self.jobs)
return self._job_list return self._job_list
def _job_format(self, job_name):
# returns job name or url based on config option
if self._jjb_config.builder['print_job_urls']:
return self._jjb_config.jenkins['url'] + \
'/job/' + '/job/'.join(job_name.split('/'))
else:
return job_name
def update_job(self, job_name, xml): def update_job(self, job_name, xml):
if self.is_job(job_name): if self.is_job(job_name):
logger.info("Reconfiguring jenkins job {0}".format(job_name)) logger.info("Reconfiguring jenkins job {0}".format(
self._job_format(job_name)))
self.jenkins.reconfig_job(job_name, xml) self.jenkins.reconfig_job(job_name, xml)
else: else:
logger.info("Creating jenkins job {0}".format(job_name)) logger.info("Creating jenkins job {0}".format(
self._job_format(job_name)))
self.jenkins.create_job(job_name, xml) self.jenkins.create_job(job_name, xml)
def is_job(self, job_name): def is_job(self, job_name):

View File

@ -126,6 +126,7 @@ class JJBConfig(object):
self.config_parser = config_parser self.config_parser = config_parser
self._section = config_section self._section = config_section
self.print_job_urls = False
self.jenkins = defaultdict(None) self.jenkins = defaultdict(None)
self.builder = defaultdict(None) self.builder = defaultdict(None)
@ -214,6 +215,11 @@ class JJBConfig(object):
flush_cache = config.getboolean('job_builder', 'flush_cache') flush_cache = config.getboolean('job_builder', 'flush_cache')
self.builder['flush_cache'] = flush_cache self.builder['flush_cache'] = flush_cache
# check the print_job_urls setting
if config.has_option('job_builder', 'print_job_urls'):
self.print_job_urls = config.getboolean('job_builder',
'print_job_urls')
# Jenkins supports access as an anonymous user, which can be used to # Jenkins supports access as an anonymous user, which can be used to
# ensure read-only behaviour when querying the version of plugins # ensure read-only behaviour when querying the version of plugins
# installed for test mode to generate XML output matching what will be # installed for test mode to generate XML output matching what will be
@ -263,6 +269,7 @@ class JJBConfig(object):
# The way we want to do things moving forward: # The way we want to do things moving forward:
self.jenkins['url'] = config.get(self._section, 'url') self.jenkins['url'] = config.get(self._section, 'url')
self.builder['print_job_urls'] = self.print_job_urls
# keep descriptions ? (used by yamlparser) # keep descriptions ? (used by yamlparser)
keep_desc = False keep_desc = False