Skip to content
Browse files

Update autojenkins/jobs.py

Adding global flag to ignore SSL certificate errors.
  • Loading branch information...
1 parent c446484 commit 3ec54cea31e2a9f87c0865e9540cb137cc5349e5 @rdodev rdodev committed Nov 2, 2012
Showing with 18 additions and 12 deletions.
  1. +18 −12 autojenkins/jobs.py
View
30 autojenkins/jobs.py
@@ -50,9 +50,10 @@ def _validate(response):
class Jenkins(object):
"""Main class to interact with a Jenkins server."""
- def __init__(self, base_url, auth=None):
+ def __init__(self, base_url, auth=None, verify_ssl_cert=True):
self.ROOT = base_url
self.auth = auth
+ self.verify_ssl_cert = verify_ssl_cert
def _build_url(self, command, *args):
"""
@@ -66,24 +67,24 @@ def _other_url(self, root, command, *args):
"""
return command.format(root, *args)
- def _get(self, url_pattern, *args, **kwargs):
+ def _get(self, url_pattern, *args):
response = requests.get(self._build_url(url_pattern, *args),
- auth=self.auth, verify=kwargs.pop('verify', True))
+ auth=self.auth, verify=self.verify_ssl_cert)
return _validate(response)
def _post(self, url_pattern, *args):
response = requests.post(self._build_url(url_pattern, *args),
- auth=self.auth)
+ auth=self.auth, verify=self.verify_ssl_cert)
return _validate(response)
- def all_jobs(self,**kwargs):
+ def all_jobs(self):
"""
Get a list of tuples with (name, color) of all jobs in the server.
Color is ``blue``, ``yellow`` or ``red`` depending on build results
(SUCCESS, UNSTABLE or FAILED).
"""
- response = self._get(LIST, **kwargs)
+ response = self._get(LIST)
jobs = eval(response.content).get('jobs', [])
return [(job['name'], job['color']) for job in jobs]
@@ -131,7 +132,7 @@ def last_result(self, jobname):
Obtain results from last execution.
"""
last_result_url = self.job_info(jobname)['lastBuild']['url']
- response = requests.get(last_result_url + API, auth=self.auth)
+ response = requests.get(last_result_url + API, auth=self.auth, verify=self.verify_ssl_cert)
return eval(response.content)
def last_success(self, jobname):
@@ -155,7 +156,8 @@ def set_config_xml(self, jobname, config):
return requests.post(self._build_url(CONFIG, jobname),
data=config,
headers={'Content-Type': 'application/xml'},
- auth=self.auth)
+ auth=self.auth,
+ verify=self.verify_ssl_cert)
def create(self, jobname, config_file, **context):
"""
@@ -172,7 +174,8 @@ def create(self, jobname, config_file, **context):
data=content,
params=params,
headers={'Content-Type': 'application/xml'},
- auth=self.auth)
+ auth=self.auth,
+ verify=self.verify_ssl_cert)
def create_copy(self, jobname, template_job, enable=True, **context):
"""
@@ -194,7 +197,8 @@ def create_copy(self, jobname, template_job, enable=True, **context):
data=config,
params={'name': jobname},
headers={'Content-Type': 'application/xml'},
- auth=self.auth)
+ auth=self.auth,
+ verify=self.verify_ssl_cert)
def transfer(self, jobname, to_server):
"""
@@ -205,15 +209,17 @@ def transfer(self, jobname, to_server):
data=config,
params={'name': jobname},
headers={'Content-Type': 'application/xml'},
- auth=self.auth)
+ auth=self.auth,
+ verify=self.verify_ssl_cert)
def copy(self, jobname, copy_from='template'):
"""
Copy a job from another one (by default from one called ``template``).
"""
params = {'name': jobname, 'mode': 'copy', 'from': copy_from}
return requests.post(self._build_url(NEWJOB), params=params,
- auth=self.auth)
+ auth=self.auth,
+ verify=self.verify_ssl_cert)
def build(self, jobname, wait=False, grace=10):
"""

0 comments on commit 3ec54ce

Please sign in to comment.
Something went wrong with that request. Please try again.