Esempio n. 1
0
    def _clone_job(self, source_job_name, new_job_name):
        """Makes a copy of this job on the dashboard with a new name

        :param str source_job_name:
            The name of the existing Jenkins job which is to have it's configuration cloned to create a new job.
            A job of this name must exist on this Jenkins instance.
        :param str new_job_name:
            the name of the newly created job whose settings will
            be an exact copy of the source job. There must be no existing
            jobs on the Jenkins dashboard with this same name.
        """
        params = {'name': new_job_name,
                  'mode': 'copy',
                  'from': source_job_name}
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}

        args = {}
        args['params'] = params
        args['data'] = ''
        args['headers'] = headers

        self._controller.post("createItem", args)

        temp_data_io = self._controller.clone(self._controller.url.rstrip("/") + "/job/" + new_job_name)
        new_job = Job._create(temp_data_io, self, new_job_name)

        # disable the newly created job so it doesn't accidentally start running
        new_job.disable()
Esempio n. 2
0
    def _light_jobs(self):
        """Private helper method used to instantiate partial job classes for improved performance

        :returns: list of abstract jobs contained within this view
        :rtype: :class:`list` of :class:`~.job.Job` objects
        """
        data = self._controller.get_api_data()
        retval = []
        for j in data['jobs']:
            temp_data_io = self._controller.clone(j['url'])
            retval.append(Job._create(temp_data_io, self._master, j['name']))

        return retval
Esempio n. 3
0
    def view_metrics(self):
        """Composes a report on the jobs contained within the view

        :return: Dictionary containing metrics about the view
        :rtype: :class:`dict`
        """
        data = self._controller.get_api_data()

        broken_jobs = []
        disabled_jobs = []
        unstable_jobs = []
        broken_job_count = 0
        disabled_jobs_count = 0
        unstable_job_count = 0

        for job in data["jobs"]:

            temp_data_io = self._controller.clone(job['url'])
            temp_job = Job._create(temp_data_io, self._master, job['name'])

            if job["color"] == "red":
                broken_job_count += 1
                broken_jobs.append(temp_job)
            elif job["color"] == "disabled":
                disabled_jobs_count += 1
                disabled_jobs.append(temp_job)
            elif job["color"] == "yellow":
                unstable_job_count += 1
                unstable_jobs.append(temp_job)

        return {"broken_jobs_count": broken_job_count,
                "disabled_jobs_count": disabled_jobs_count,
                "unstable_jobs_count": unstable_job_count,
                "broken_jobs": broken_jobs,
                "unstable_jobs": unstable_jobs,
                "disabled_jobs": disabled_jobs}