From b76ed1629d1cda2204b51abb8e1ed8b09ba52d3a Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 10 May 2017 11:49:06 +0100 Subject: [PATCH] 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 --- doc/source/execution.rst | 5 +++++ jenkins_jobs/builder.py | 14 ++++++++++++-- jenkins_jobs/config.py | 7 +++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/doc/source/execution.rst b/doc/source/execution.rst index 1006e818b..1a67a8ba7 100644 --- a/doc/source/execution.rst +++ b/doc/source/execution.rst @@ -52,6 +52,11 @@ job_builder section string, allowing you to use those strings without having to define all the 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 ^^^^^^^^^^^^^^^ diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index 7626d461e..04b73e10c 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -104,12 +104,22 @@ class JenkinsManager(object): self._job_list = set(job['fullname'] for job in self.jobs) 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): 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) 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) def is_job(self, job_name): diff --git a/jenkins_jobs/config.py b/jenkins_jobs/config.py index 81438e132..7b0c2a1d8 100644 --- a/jenkins_jobs/config.py +++ b/jenkins_jobs/config.py @@ -126,6 +126,7 @@ class JJBConfig(object): self.config_parser = config_parser self._section = config_section + self.print_job_urls = False self.jenkins = defaultdict(None) self.builder = defaultdict(None) @@ -214,6 +215,11 @@ class JJBConfig(object): flush_cache = config.getboolean('job_builder', '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 # ensure read-only behaviour when querying the version of plugins # 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: self.jenkins['url'] = config.get(self._section, 'url') + self.builder['print_job_urls'] = self.print_job_urls # keep descriptions ? (used by yamlparser) keep_desc = False