def execute(self, options, jjb_config):
        builder = JenkinsManager(jjb_config)

        reach = set()
        if options.del_jobs and options.del_views:
            raise JenkinsJobsException('"--views-only" and "--jobs-only" cannot be used together.')
        elif options.del_jobs and not options.del_views:
            reach.add("jobs")
        elif options.del_views and not options.del_jobs:
            reach.add("views")
        else:
            reach.update(("jobs", "views"))

        if not utils.confirm(
            "Sure you want to delete *ALL* {} from Jenkins "
            "server?\n(including those not managed by Jenkins "
            "Job Builder)".format(" AND ".join(reach))
        ):
            sys.exit("Aborted")

        if options.del_jobs:
            logger.info("Deleting all jobs")
            builder.delete_all_jobs()

        if options.del_views:
            logger.info("Deleting all views")
            builder.delete_all_views()
Ejemplo n.º 2
0
    def execute(self, options, jjb_config):
        builder = JenkinsManager(jjb_config)

        if options.del_jobs and options.del_views:
            raise JenkinsJobsException(
                '"--views-only" and "--jobs-only" cannot be used together.')

        fn = options.path
        registry = ModuleRegistry(jjb_config, builder.plugins_list)
        parser = YamlParser(jjb_config)

        if fn:
            parser.load_files(fn)
            parser.expandYaml(registry, options.name)
            jobs = [j["name"] for j in parser.jobs]
            views = [v["name"] for v in parser.views]
        else:
            jobs = options.name
            views = options.name

        if options.del_jobs:
            builder.delete_jobs(jobs)
        elif options.del_views:
            builder.delete_views(views)
        else:
            builder.delete_jobs(jobs)
            builder.delete_views(views)
Ejemplo n.º 3
0
    def execute(self, options, jjb_config):
        builder = JenkinsManager(jjb_config)

        if options.del_jobs and options.del_views:
            raise JenkinsJobsException(
                '"--views-only" and "--jobs-only" cannot be used together.')

        fn = options.path
        registry = ModuleRegistry(jjb_config, builder.plugins_list)
        parser = YamlParser(jjb_config)

        if fn:
            parser.load_files(fn)
            parser.expandYaml(registry, options.name)
            jobs = [j['name'] for j in parser.jobs]
            views = [v['name'] for v in parser.views]
        else:
            jobs = options.name
            views = options.name

        if options.del_jobs:
            builder.delete_jobs(jobs)
        elif options.del_views:
            builder.delete_views(views)
        else:
            builder.delete_jobs(jobs)
            builder.delete_views(views)
Ejemplo n.º 4
0
    def execute(self, options, jjb_config):
        builder = JenkinsManager(jjb_config)

        if not utils.confirm(
                'Sure you want to delete *ALL* jobs from Jenkins '
                'server?\n(including those not managed by Jenkins '
                'Job Builder)'):
            sys.exit('Aborted')

        logger.info("Deleting all jobs")
        builder.delete_all_jobs()
Ejemplo n.º 5
0
    def execute(self, options, jjb_config):
        builder = JenkinsManager(jjb_config)

        if not utils.confirm(
                'Sure you want to delete *ALL* jobs from Jenkins '
                'server?\n(including those not managed by Jenkins '
                'Job Builder)'):
            sys.exit('Aborted')

        logger.info("Deleting all jobs")
        builder.delete_all_jobs()
Ejemplo n.º 6
0
    def execute(self, options, jjb_config):
        builder = JenkinsManager(jjb_config)

        fn = options.path
        registry = ModuleRegistry(jjb_config, builder.plugins_list)
        parser = YamlParser(jjb_config)

        if fn:
            parser.load_files(fn)
            parser.expandYaml(registry, options.name)
            jobs = [j["name"] for j in parser.jobs]
        else:
            jobs = options.name

        builder.delete_jobs(jobs)
Ejemplo n.º 7
0
    def execute(self, options, jjb_config):
        builder = JenkinsManager(jjb_config)

        fn = options.path
        registry = ModuleRegistry(jjb_config, builder.plugins_list)
        parser = YamlParser(jjb_config)

        if fn:
            parser.load_files(fn)
            parser.expandYaml(registry, options.name)
            jobs = [j['name'] for j in parser.jobs]
        else:
            jobs = options.name

        builder.delete_jobs(jobs)
Ejemplo n.º 8
0
    def _generate_xmljobs(self, options, jjb_config=None):
        builder = JenkinsManager(jjb_config)

        logger.info("Updating jobs in {0} ({1})".format(
            options.path, options.names))
        orig = time.time()

        # Generate XML
        parser = YamlParser(jjb_config)
        registry = ModuleRegistry(jjb_config, parser, builder.plugins_list)
        xml_job_generator = XmlJobGenerator(registry)
        xml_view_generator = XmlViewGenerator(registry)

        parser.load_files(options.path)
        registry.set_parser_data(parser.data)

        job_data_list, view_data_list = parser.expandYaml(
            registry, options.names)

        xml_jobs = xml_job_generator.generateXML(job_data_list)
        xml_views = xml_view_generator.generateXML(view_data_list)

        jobs = parser.jobs
        step = time.time()
        logging.debug('%d XML files generated in %ss', len(jobs),
                      str(step - orig))

        return builder, xml_jobs, xml_views
Ejemplo n.º 9
0
    def execute(self, options, jjb_config):
        builder = JenkinsManager(jjb_config)

        reach = set()
        if options.del_jobs and options.del_views:
            raise JenkinsJobsException(
                '"--views-only" and "--jobs-only" cannot be used together.')
        elif options.del_jobs and not options.del_views:
            reach.add('jobs')
        elif options.del_views and not options.del_jobs:
            reach.add('views')
        else:
            reach.update(('jobs', 'views'))

        if not utils.confirm(
                'Sure you want to delete *ALL* {} from Jenkins '
                'server?\n(including those not managed by Jenkins '
                'Job Builder)'.format(" AND ".join(reach))):
            sys.exit('Aborted')

        if 'jobs' in reach:
            logger.info("Deleting all jobs")
            builder.delete_all_jobs()

        if 'views' in reach:
            logger.info("Deleting all views")
            builder.delete_all_views()
Ejemplo n.º 10
0
    def get_jobs(self, wd, name):
        ini_path = "{}/{}.ini".format(wd, name)
        config_path = "{}/config.yaml".format(wd)

        args = ["--conf", ini_path, "test", config_path]
        jjb = self.get_jjb(args)
        builder = JenkinsManager(jjb.jjb_config)
        registry = ModuleRegistry(jjb.jjb_config, builder.plugins_list)
        parser = YamlParser(jjb.jjb_config)
        parser.load_files(jjb.options.path)
        jobs, _ = parser.expandYaml(registry, jjb.options.names)

        return jobs
    def execute(self, options, jjb_config):
        builder = JenkinsManager(jjb_config)
        plugin_data = builder.jenkins.get_plugins_info()
        plugins_info = []
        for plugin in plugin_data:
            info = {
                'longName': str(plugin['longName']),
                'shortName': str(plugin['shortName']),
                'version': str(plugin['version']),
            }
            plugins_info.append(info)

        if options.plugins_info_file:
            with open(options.plugins_info_file, 'w') as outfile:
                outfile.write(yaml.dump(plugins_info))
            logger.info("Generated {} file".format(options.plugins_info_file))
        else:
            print(yaml.dump(plugins_info))
Ejemplo n.º 12
0
    def get_job_webhooks_data(self):
        job_webhooks_data = {}
        for name, wd in self.working_dirs.items():
            ini_path = '{}/{}.ini'.format(wd, name)
            config_path = '{}/config.yaml'.format(wd)

            args = ['--conf', ini_path, 'test', config_path]
            jjb = self.get_jjb(args)
            builder = JenkinsManager(jjb.jjb_config)
            registry = ModuleRegistry(jjb.jjb_config, builder.plugins_list)
            parser = YamlParser(jjb.jjb_config)
            parser.load_files(jjb.options.path)

            jobs, _ = parser.expandYaml(registry, jjb.options.names)

            for job in jobs:
                try:
                    project_url_raw = job['properties'][0]['github']['url']
                    if 'https://github.com' in project_url_raw:
                        continue
                    job_url = \
                        '{}/project/{}'.format(self.instances[name],
                                               job['name'])
                    project_url = \
                        project_url_raw.strip('/').replace('.git', '')
                    gitlab_triggers = job['triggers'][0]['gitlab']
                    mr_trigger = gitlab_triggers['trigger-merge-request']
                    trigger = 'mr' if mr_trigger else 'push'
                    hook = {
                        'job_url': job_url,
                        'trigger': trigger,
                    }
                    job_webhooks_data.setdefault(project_url, [])
                    job_webhooks_data[project_url].append(hook)
                except KeyError:
                    continue
        return job_webhooks_data