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
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