def create_view(self): """Creates new empty view""" try: self.server.create_view( self.view_args.name, jenkins.EMPTY_VIEW_CONFIG_XML) logger.info("Created new view: %s", self.view_args.name) except Exception as e: raise exception.JcliException(e)
def node_info(self): """Print information on a specific plugin.""" if not self.server.node_exists(self.node_args.name): raise exception.JcliException("There is node with such name: %s", self.node_args.name) try: node_json = self.server.get_node_info(self.node_args.name) logger.info("Name: %s", self.node_args.name) logger.info("Idle? %s", node_json['idle']) logger.info("Number of executors: %s", node_json['numExecutors']) logger.info("Offline? %s", node_json['offline']) if node_json['offline'] and node_json['offlineCauseReason']: logger.info("Cause: %s", node_json['offlineCauseReason']) except Exception as e: raise exception.JcliException(e)
def copy_job(self): """Copies job""" try: self.server.copy_job(self.job_args.source_job_name, self.job_args.dest_job_name) logger.info("Done copying: {}. The new job is called: {}".format( self.job_args.source_job_name, self.job_args.dest_job_name)) except Exception as e: raise exception.JcliException(e)
def list_plugins(self): """Print list of all the plugins""" try: plugins = self.server.get_plugins() for name, info in plugins.items(): logger.info(name[0]) except Exception as e: raise exception.JcliException(e)
def create_node(self): """Creates node.""" name = self.node_args.name if self.server.node_exists(name): raise exception.JcliException( "There is already node with this name: %s", name) try: self.server.create_node(name, self.node_args.executors, self.node_args.description, self.node_args.remotefs, self.node_args.labels, self.node_args.exclusive) logger.info("Node created: %s", name) except Exception: raise exception.JcliException("Couldn't create node: %s", Exception.message)
def delete_node(self): """Removes node from the server""" if self.node_args.name: try: self.server.delete_node(self.node_args.name) except Exception: raise exception.JcliException("No such node: {}".format( self.node_args.name)) logger.info("Removed node: %s", self.node_args.name) else: logger.info("No name provided. Exiting...")
def enable_job(self): """Enables job""" for name in allof(self.job_args.name): try: self.server.enable_job(name) except Exception: raise exception.JcliException("No such job: {}".format(name)) logger.info("Enabled job: %s", name)
def delete_job(self): """Removes job from the server""" if self.job_args.name: for name in allof(self.job_args.name): try: self.server.delete_job(name) logger.info("Removed job: {}".format(name)) except Exception as e: raise exception.JcliException(e) else: logger.info("No name provided. Exiting...")
def delete_view(self): """Removes view from the server""" if self.view_args.name: try: self.server.delete_view(self.view_args.name) except Exception: raise exception.JcliException( "No such view: {}".format(self.view_args.name)) logger.info("Removed view: %s", self.view_args.name) else: logger.info("No name provided. Exiting...")
def rename_view(self): """Rename the specific view. """ view_config = self.server.get_view_config(self.view_args.name) new_config = re.sub(r"<name>.*</name>", "<name>%s</name>" % self.view_args.new_name, view_config) try: self.server.reconfig_view(self.view_args.name, new_config) logger.info("Renamed. The new name: %s", self.view_args.new_name) except Exception as e: raise exception.JcliException(e)
def stop_build(self): """Stops running build.""" try: if not self.build_args.build_number: build_number = int(self.server.get_job_info( self.build_args.job_name[0])['lastBuild']['number']) else: build_number = self.build_args.build_number self.server.stop_build(self.build_args.job_name[0], build_number) logger.info( "Stopped build {} for {}".format(build_number, self.build_args.job_name[0])) except jenkins.NotFoundException as e: raise exception.JcliJobNotFound(self.build_args.job_name[0]) except Exception as e: raise exception.JcliException(e)
def last_build(self): """Output information on last build""" try: last_build_number = self.server.get_job_info( self.job_args.name)['lastCompletedBuild']['number'] build_info = self.server.get_job_info(self.job_args.name, last_build_number) logger.info( "=================== Last build summary ===================\n") logger.info("Build Number: {}".format(last_build_number)) # Log SCMs logger.info("\nSCMs:\n") for scm in build_info['scm']['configuredSCMs']: for info in scm['userRemoteConfigs']: logger.info(" Url: {}".format(info['url'])) logger.info(" Refspec: {}\n -----".format( info['refspec'])) # Log Parameters logger.info("\n\nParameters:\n") for param in build_info['property'][6]['parameterDefinitions']: logger.info(" Parameter: {}\n Value: {}\n -----".format( param['defaultParameterValue']['name'], param['defaultParameterValue']['value'])) # Log general build info logger.info("\n\nBuild Duration: {}".format( build_info['lastBuild']['duration'])) logger.info("Built on slave: {}".format( build_info['lastBuild']['builtOn'])) logger.info("URL: {}".format(build_info['lastBuild']['url'])) logger.info("\nResult: {}".format( build_info['lastBuild']['result'])) except Exception as e: raise exception.JcliException(e)
def plugin_info(self): """Print information on a specific plugin.""" plugin_name = self.plugin_args.name[0] try: plugin_json = self.server.get_plugin_info(plugin_name) if plugin_json: logger.info("Name: %s", plugin_name) logger.info("Version: %s", plugin_json['version']) logger.info("Enabled?: %s", plugin_json['enabled']) logger.info("Has update?: %s", plugin_json['hasUpdate']) logger.info("Official page: %s", plugin_json['url']) logger.info("Dependencies:") for dep in plugin_json['dependencies']: logger.info("\tName: %s", dep['shortName']) logger.info("\tVersion: %s\n", dep['version']) else: logger.info("No such plugin: %s", plugin_name) except Exception as e: raise exception.JcliException(e)