def delete_job_from_jenkins(job_pk): """ Deletes a job from its Jenkins server. """ job = Job.objects.get(pk=job_pk) xml = get_job_xml_for_upload(job, job.server) client = job.server.get_client() return client.delete_job(job.name)
def test_get_job_xml_for_upload_strips_leading_spaces(self): """ If we attempt to upload an XML document that has leading whitespace, then Jenkins will fail with a weird error. "processing instruction can not have PITarget with reserveld xml" """ jobtype = JobTypeFactory.create(config_xml="\ntesting") job = JobFactory.create(jobtype=jobtype) self.assertEqual("testing", get_job_xml_for_upload(job))
def test_get_job_xml_for_upload(self): """ get_job_xml_for_upload should take a job and return the XML that needs to be uploaded to build the job. """ jobtype = JobTypeFactory.create(config_xml=template_config) job = JobFactory.create(jobtype=jobtype) xml_for_upload = get_job_xml_for_upload(job) expected_url = get_notifications_url("http://example.com/") self.assertIn(job.jobtype.description, xml_for_upload) self.assertIn(expected_url, xml_for_upload)
def test_get_job_xml_for_upload(self): """ get_job_xml_for_upload should take a job and return the XML that needs to be uploaded to build the job. """ jobtype = JobTypeFactory.create(config_xml=template_config) job = JobFactory.create(jobtype=jobtype) server = JenkinsServerFactory.create() xml_for_upload = get_job_xml_for_upload(job, server) expected_url = get_notifications_url("http://example.com/", server) self.assertIn(job.jobtype.description, xml_for_upload) self.assertIn(expected_url, xml_for_upload)
def push_job_to_jenkins(job_pk): """ Create or update a job in the server with the config. """ job = Job.objects.get(pk=job_pk) xml = get_job_xml_for_upload(job, job.server) client = job.server.get_client() if client.has_job(job.name): job = client.get_job(job.name) job.update_config(xml) else: client.create_job(job.name, xml)
def test_get_job_xml_for_upload_strips_leading_spaces(self): """ If we attempt to upload an XML document that has leading whitespace, then Jenkins will fail with a weird error. "processing instruction can not have PITarget with reserveld xml" """ empty_config = """\n <?xml version='1.0' encoding='UTF-8'?> <project> <properties> <hudson.model.ParametersDefinitionProperty> <parameterDefinitions /> </hudson.model.ParametersDefinitionProperty> </properties> </project> """ server = JenkinsServerFactory.create() jobtype = JobTypeFactory.create(config_xml=empty_config) job = JobFactory.create(jobtype=jobtype) self.assertTrue(get_job_xml_for_upload(job, server)[0] != "\n")