示例#1
0
    def create_job(self, job_name, job_type):
        """Creates a new job on this Jenkins instance

        :param str job_name:
            The name for the job to be created.
            expected to be universally unique on this instance of Jenkins
        :param str job_type:
            descriptive type for the base configuration of this new job
            for a list of currently supported job types see :meth:`.job_types`
        """
        params = {'name': job_name}
        headers = {'Content-Type': 'text/xml'}

        args = {}
        args['params'] = params
        args['headers'] = headers
        args['data'] = Job.template_config_xml(job_type)

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

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

        # Sanity check - make sure the job actually exists by checking its name
        assert new_job.name == job_name

        #disable the newly created job so it doesn't accidentally start running
        new_job.disable()

        return new_job
示例#2
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()
示例#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._api.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_job = Job.instantiate(job, self._api)

            if temp_job.is_failing:
                broken_job_count += 1
                broken_jobs.append(temp_job)
            elif temp_job.is_disabled:
                disabled_jobs_count += 1
                disabled_jobs.append(temp_job)
            elif temp_job.is_unstable:
                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}
示例#4
0
 def job_types(self):
     """
     :returns: a list of Jenkins job types currently supported by this instance of PyJen
              Elements from this list may be used when creating new jobs on this Jenkins instance,
              so long as the accompanying job type is supported by the live Jenkins server
     :rtype: :class:`list` of :class:`str`
     """
     return Job.supported_types()
示例#5
0
    def jobs(self):
        """Gets all jobs managed by this Jenkins instance

        :rtype:  :class:`list` of :class:`~.job.Job` objects
        """
        data = self._api.get_api_data(query_params="depth=0")

        retval = list()
        for j in data['jobs']:
            retval.append(Job.instantiate(j, self._api))

        return retval
示例#6
0
    def jobs(self):
        """Gets a list of all jobs contained in this folder

        :rtype: :class:`list` of :class:`~.job.Job`
        """
        data = self._api.get_api_data()

        retval = list()
        for tjob in data['jobs']:
            retval.append(Job.instantiate(tjob, self._api))

        return retval
示例#7
0
文件: jenkins.py 项目: tylerml/pyjen
    def jobs(self):
        """Gets all jobs managed by this Jenkins instance

        :rtype:  :class:`list` of :class:`~.job.Job` objects
        """
        data = self._api.get_api_data(query_params="depth=2")

        retval = list()
        for j in data['jobs']:
            retval.append(Job.instantiate(j, self._api))

        return retval
示例#8
0
    def jobs(self):
        """Gets all branch jobs managed by this multibranch pipeline

        :rtype: :class:`list` of :class:`~.pipelinejob.PipelineJob`
        """
        data = self._api.get_api_data(query_params="depth=0")

        retval = list()
        for j in data["jobs"]:
            retval.append(Job.instantiate(j, self._api))

        return retval
    def jobs(self):
        """Gets all branch jobs managed by this multibranch pipeline

        :rtype: :class:`list` of :class:`~.pipelinejob.PipelineJob`
        """
        data = self._api.get_api_data(query_params="depth=0")

        retval = list()
        for j in data["jobs"]:
            retval.append(Job.instantiate(j, self._api))

        return retval
示例#10
0
    def jobs(self):
        """Gets a list of all jobs contained in this folder

        :rtype: :class:`list` of :class:`~.job.Job`
        """
        data = self._api.get_api_data()

        retval = list()
        for tjob in data['jobs']:
            retval.append(Job.instantiate(tjob, self._api))

        return retval
示例#11
0
def test_load_all_job_plugins():
    plugins = Job.get_supported_plugins()
    assert plugins is not None
    assert isinstance(plugins, list)
    assert len(plugins) > 0

    mock_api = MagicMock()
    expected_name = "FakeName"
    mock_api.get_api_data.return_value = {"name": expected_name}
    for cur_plugin in plugins:
        job = cur_plugin(mock_api)
        assert job.name == expected_name
        assert isinstance(job, Job)
示例#12
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
示例#13
0
def test_load_all_job_plugins():
    plugins = Job.get_supported_plugins()
    assert plugins is not None
    assert isinstance(plugins, list)
    assert len(plugins) > 0

    mock_api = MagicMock()
    expected_name = "FakeName"
    mock_api.get_api_data.return_value = {
        "name": expected_name
    }
    for cur_plugin in plugins:
        job = cur_plugin(mock_api)
        assert job.name == expected_name
        assert isinstance(job, Job)
示例#14
0
    def downstream_jobs(self):
        """Gets the list of jobs to be triggered after this job completes

        :returns: A list of 0 or more jobs which depend on this one
        :rtype:  :class:`list` of :class:`~.job.Job` objects
        """
        data = self._api.get_api_data()

        jobs = data['downstreamProjects']

        retval = list()

        for j in jobs:
            retval.append(Job.instantiate(j, self._api))

        return retval
示例#15
0
    def upstream_jobs(self):
        """Gets the list of upstream dependencies for this job

        :returns: A list of 0 or more jobs that this job depends on
        :rtype: :class:`list` of :class:`~.job.Job` objects
        """
        data = self._api.get_api_data()

        jobs = data['upstreamProjects']

        retval = list()

        for j in jobs:
            retval.append(Job.instantiate(j, self._api))

        return retval
示例#16
0
文件: jenkins.py 项目: tylerml/pyjen
    def find_job(self, job_name):
        """Searches all jobs managed by this Jenkins instance for a specific job

        .. seealso: :py:meth:`.get_job`

        :param str job_name: the name of the job to search for
        :returns:
            If a job with the specified name can be found, and object to manage
            the job will be returned, otherwise None
        :rtype: :class:`~.job.Job`
        """
        data = self._api.get_api_data()

        for cur_job in data['jobs']:
            if cur_job['name'] == job_name:
                return Job.instantiate(cur_job, self._api)

        return None
示例#17
0
    def find_job(self, job_name):
        """Searches all jobs managed by this Jenkins instance for a specific job

        .. seealso: :py:meth:`.get_job`

        :param str job_name: the name of the job to search for
        :returns:
            If a job with the specified name can be found, and object to manage
            the job will be returned, otherwise None
        :rtype: :class:`~.job.Job`
        """
        data = self._api.get_api_data()

        for cur_job in data['jobs']:
            if cur_job['name'] == job_name:
                return Job.instantiate(cur_job, self._api)

        return None
示例#18
0
    def find_job(self, job_name):
        """Searches all jobs managed by this Jenkins instance for a specific job

        .. seealso: :py:meth:`.get_job`

        :param str job_name: the name of the job to search for
        :returns:
            If a job with the specified name can be found, and object to manage the job will be returned, otherwise None
        :rtype: :class:`~.job.Job`
        """
        data = self._controller.get_api_data()
        tjobs = data['jobs']

        for tjob in tjobs:
            if tjob['name'] == job_name:
                new_io_obj = self._controller.clone(tjob['url'])
                return Job.create(new_io_obj, self)

        return None
示例#19
0
    def jobs(self):
        """Gets a list of jobs associated with this view

        Views are simply filters to help organize jobs on the
        Jenkins dashboard. This method returns the set of jobs
        that meet the requirements of the filter associated
        with this view.

        :returns: list of 0 or more jobs that are included in this view
        :rtype:  :class:`list` of :class:`~.job.Job` objects
        """
        data = self._api.get_api_data(query_params="depth=2")

        view_jobs = data['jobs']

        retval = []
        for j in view_jobs:
            retval.append(Job.instantiate(j, self._api))

        return retval
示例#20
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}
示例#21
0
    def test_supported_types(self):
        actual = Job.supported_types()

        self.assertIn("project", actual)
        self.assertGreater(len(actual), 1)