From 63a08ef3d26f124997848714a4d3f274d1906b8b Mon Sep 17 00:00:00 2001 From: Ismael Viamontes Marrero Date: Wed, 25 Jun 2014 18:56:11 -0300 Subject: [PATCH] Added support for creates views and creates jobs into view --- autojenkins/jobs.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/autojenkins/jobs.py b/autojenkins/jobs.py index ddfc6bb..ef864c4 100644 --- a/autojenkins/jobs.py +++ b/autojenkins/jobs.py @@ -46,7 +46,8 @@ def __str__(self): LAST_REPORT = '{0}/job/{1}/lastBuild/testReport/' + API ENABLE = '{0}/job/{1}/enable' DISABLE = '{0}/job/{1}/disable' - +NEWVIEW = '{0}/createView' +NEW_JOB_INTO_VIEW = '{0}/view/{1}/createItem' class HttpStatusError(Exception): pass @@ -351,3 +352,36 @@ def wait_for_build(self, jobname, poll_interval=3): sys.stdout.write('.') sys.stdout.flush() print('') + + def createJobIntoView(self, jobname, viewname, config_file, **context): + """ + Create a job into a view from a configuration file. + """ + params = {'name': jobname} + with open(config_file) as file: + content = file.read() + + template = Template(content) + content = template.render(**context) + + return self._build_post(NEW_JOB_INTO_VIEW, + viewname, + data=content, + params=params, + headers={'Content-Type': 'application/xml'}) + + def create_view(self, viewname, config_file, **context): + """ + Create a view from a configuration file. + """ + params = {'name': viewname} + with open(config_file) as file: + content = file.read() + + template = Template(content) + content = template.render(**context) + + return self._build_post(NEWVIEW, + data=content, + params=params, + headers={'Content-Type': 'application/xml'})