def generate_jjb_jobs(out_dir): jjb_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../jjb') jjb_test = JenkinsJobs(args=['test', jjb_dir, '-o', out_dir]) # Fake the list of plugins to skip retrieval jjb_test.jjb_config.builder['plugins_info'] = [] jjb_test.execute()
def generate_jjb_jobs(out_dir): jjb_dir = os.path.join( os.path.dirname(os.path.abspath(__file__)), '../jjb') jjb_test = JenkinsJobs(args=['test', jjb_dir, '-o', out_dir]) # Fake the list of plugins to skip retrieval jjb_test.jjb_config.builder['plugins_info'] = [] jjb_test.execute()
def run_jjb(self, name, jobname=None): filename = os.path.join(fixtures_path, name + '.xml') root = get_xml_root(filename=filename) if jobname is None: jobname = name yaml = root_to_yaml(root, jobname) # Run this wrecker YAML thru JJB. with tempfile.NamedTemporaryFile('w') as temp: temp.write(yaml) temp.flush() jjb = JenkinsJobs(['test', temp.name]) assert jjb.execute() is None
def manage_jobs(cmd_args: JobsCmdArgs): # do not import that at module level to avoid too early # logging initialization that happens in JJB itself # pylint: disable=import-outside-toplevel from jenkins_jobs.cli.entry import JenkinsJobs cmd_args.action = defs.JobsActionT(cmd_args.action) gen_jobs_ini(cmd_args.config) utils.set_ssl_verify( cmd_args.config[defs.ConfigSectionT.GLOBAL.value]['ssl_verify']) # defs.JobsActionT.UPDATE or defs.JobsActionT.DELETE argv = [ '--conf', str(defs.JOBS_CONFIG), '-l', logging.getLevelName(logger.getEffectiveLevel()), cmd_args.action.value, '--recursive' ] if cmd_args.jjb_args: # TODO 'split' might be too naive in some cases argv.extend(cmd_args.jjb_args.split()) argv.append(str(defs.JOBS_DIR)) logger.debug(f"Calling JJB with the following args: {argv}") return JenkinsJobs(argv).execute()
def update(self, delete_old, workers, path=None, file=None, jobs=None, **kwargs): action_options = [ 'update', '--workers', str(workers), ] if delete_old: action_options.insert(1, '--delete_old') if path is not None and jobs is not None: action_options.append(path) action_options.extend(jobs) elif path is not None and file is not None: action_options.append(path + '/' + file) elif path is not None: action_options.append(path) else: raise Exception('Incorrect options. File or path with job files should be provided') self.options.extend(action_options) jjb_configs = JenkinsJobs(self.options) jjb_configs.jjb_config.jenkins['url'] = self.jenkins_server num_updated_jobs, num_updated_views = \ self.executor.execute(options=jjb_configs.options, jjb_config=jjb_configs.jjb_config) if num_updated_jobs == 0 & num_updated_views == 0: self.result['original_message'] = 'Nothing changed' self.result['message'] = 'goodbye' else: self.result['changed'] = True self.result['original_message'] = 'Changed jobs: {}. Changed views: {}.'.format(num_updated_jobs, num_updated_views) self.result['message'] = 'goodbye' return self.result
def get_jjb(self, args): from jenkins_jobs.cli.entry import JenkinsJobs return JenkinsJobs(args)